Hi, thanks to anybody that reads or replies this thread.

I have a form that uploads both, data and files , i get the form to upload the data correctly to mysql but the file name dont get there , I also would like the rename the image to another name for example i have the value $code , i would like to rename the image to $code.jpg or something like that then post the new value as $image or something to the table on MySQL

So the question is. How do i rename a image to the name i want and then post it to the table on mysql database , my file upload code is


$uploaddir = 'images/';
$uploadfile = $uploaddir . basename($_FILES['imagen']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['imagen']['tmp_name'], $uploadfile)) {
   echo "File is valid, and was successfully uploaded.\n";
} else {
   echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";
 

thanks again for your help 😃

    nevermind i found the solution using [MAN]rename()[/MAN]

    i changed my code to :

    
    $uploaddir = 'images/';
    $uploadfile = $uploaddir . basename($_FILES['imagen']['name']);
    $renamed = $uploaddir . $codigo . ".jpg";
    
    echo '<pre>';
    if (move_uploaded_file($_FILES['imagen']['tmp_name'], $uploadfile)) {
       echo "File is valid, and was successfully uploaded.\n";
    } else {
       echo "Possible file upload attack!\n";
    }
    
    echo 'Here is some more debugging info:';
    print_r($_FILES);
    
    print "</pre>";
    rename($uploadfile, $renamed);
    
    

      Just so you know, you can name the uploaded file whatever you want with move_uploaded_file().

        Write a Reply...