Ver Mensaje Individual
  #5 (permalink)  
Antiguo 02/09/2017, 20:16
pcid
Usuario no validado
 
Fecha de Ingreso: abril-2008
Mensajes: 50
Antigüedad: 18 años, 5 meses
Puntos: 16
Respuesta: Editar Imagen

En pocas palabras: Sugiero que antepongas fecha y hora en formato yyyymmdd-HHmmss al nombre del archivo.

Saludos,

PCID.

Código PHP:
<?php
    $target_dir 
= "uploads/";
    if (!
file_exists($target_dir)) mkdir($target_dir);

    
$uploadOk = FALSE;
    
$sql = "";
    if (isset(
$_POST['sb']))
    {

        if (
$_FILES['img_profile']['size'] != 0)
        {
            if (!
file_exists($target_dir)) mkdir($target_dir);

            
$target_file = $target_dir . date('Ymd-His') . '_' . basename($_FILES["img_profile"]["name"]);
            
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
            
$check = getimagesize($_FILES["img_profile"]["tmp_name"]);
            
$uploadOk = ($check !== false);
        }

        if (
$uploadOk)
        {
            
move_uploaded_file($_FILES["img_profile"]["tmp_name"], $target_file);

            
$_POST['nombre'] = 'nombre value…';
            
$_POST['username'] = 'username value…';
            
$_POST['email'] = 'email value…';
            
$_POST['password'] = 'password value…';
            
$_POST['celphone'] = 'celphone value…';
            
$_POST['cod_us'] = 'cod_us value…';



            
$sql = "update login set nombre = '" . $_POST["nombre"] . "',"
                    
. " username = '" . $_POST["username"] . "',"
                    
. " email = '" . $_POST["email"] . "',"
                    
. " password = '" . $_POST["password"] . "',"
                    
. " celphone = '" . $_POST["celphone"] . "',"
                    
. " img_profile = '" . $target_file . "'"
                
. " where cod_us='" . $_POST["cod_us"]."'";



        }

    }

?>

<form method="post" enctype="multipart/form-data">
    <input id="img_profile" name="img_profile" type="file"/>
    <hr/>
    <input id="sb" name="sb" type="submit" value="Upload file"/>
</form>
<hr/>
<?php echo $sql; ?>