Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/05/2011, 12:33
Avatar de skamter
skamter
 
Fecha de Ingreso: agosto-2009
Mensajes: 72
Antigüedad: 14 años, 9 meses
Puntos: 1
Subir archivo PHP, nombre de archivo.

Buenas, tengo un formulario hecho en php en el que puedo modificar registros de la base de datos sql, el problema esta en que no se como hacer para que el archivo que subo, se llame como el cf_id del producto, es decir, si subo el archivo "foto.jpg", que se renombre automaticamente al cf_id que tiene la entrada "26.jpg" por ejemplo.
Lo que tengo por ahora es esto:

El formulario:
Código PHP:
<?php
require("conexion.php");
require(
"funciones.php");

$uid getParam($_GET["uid"], "");
$action getParam($_GET["action"], "");

if (
$action == "edit") {
    
$uid sqlValue($_POST["uid"], "int");
    
$marca sqlValue($_POST["marca"], "int");
    
$modelo sqlValue($_POST["modelo"], "int");
    
$serial sqlValue($_POST["serial"], "int");
    
$email sqlValue($_POST["email"], "int");
    
$phone sqlValue($_POST["phone"], "int");
    
    
$sql "UPDATE tabla SET ";
    
$sql.= "marca=".$marca.", modelo=".$modelo.", serial=".$serial.", email=".$email.", phone=".$phone." ";
    
$sql.= "WHERE uid=".$uid;
    
mysql_query($sql$conexion);
    
header("location: http://www.web.com/index.php?option=com_editando");
}

$sql "SELECT marca, modelo, serial, email, phone, uid FROM tabla WHERE uid = ".sqlValue($uid"int");
$queEmp mysql_query($sql$conexion);
$rsEmp mysql_fetch_assoc($queEmp);
$total mysql_num_rows($queEmp);
if (
$total == 0) {
    
header("location: http://www.web.com/index.php?option=com_editando");
    exit;
}


?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h3><font size="6" color="#0077C6">Editar mi producto</font></h3>
<p>&nbsp;</p>
  <input type="hidden" id="uid" name="uid" value="<?php echo $rsEmp["uid"]; ?>" />
<form action="/pruebasposesion/upload.php" method="post" enctype="multipart/form-data">
  <p align="center">
  <input name="archivo" type="file" size="35" />
  <input name="enviar" type="submit" value="Upload File" />
  <input name="action" type="hidden" value="upload" />     
    </p>
</form>
</body>
</html>
Y el upload.php:
Código PHP:
<html>
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=http://www.numbaza.com/index.php?option=com_editar">
</html>
<?php  
$status 
"";
if (
$_POST["action"] == "upload") {
    
// obtenemos los datos del archivo
    
$tamano $_FILES["archivo"]['size'];
    
$tipo $_FILES["archivo"]['type'];
    
$archivo $_FILES["archivo"]['name'];
    
$prefijo substr(md5(uniqid(rand())),0,6);
   
    if (
$archivo != "") {
        
// guardamos el archivo a la carpeta files
        
$destino =  "uploads/".$prefijo."_".$archivo;
        if (
copy($_FILES['archivo']['tmp_name'],$destino)) {
            
$status "Archivo subido: <b>".$archivo."</b>";
        } else {
            
$status "Error al subir el archivo";
        }
    } else {
        
$status "Error al subir archivo";
    }
}
?>