I'm currently working on an upload script for my site. When you upload the file it gives it a random name. This part of it works fine. It uploads correctly and renames it at random. But for some reason when I try to get it to save the filename to the DB it won't work. It posts the file name prior to the name change.
For example if I upload a file named junk.jpg and it changes the file name 10080808junk.jpg it will upload 10080808junk.jpg to the folder it's supposed to but save junk.jpg to the DB. Any ideas? Here is my code and keep in mind at the end of the code $img is the name of the field in the DB where it will be stored so I'm trying to give it the value of the correct filename to be saved to the DB. Thanks in advance!
$uploaddir = '/home/evanbart/www/nbl/cms/uploads/breaking_news/photos/';
$picname = $_FILES['userfile']['name'];
$uploadfile = $uploaddir . rand(1000000000,9999999999) . $picname;
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$text="File is valid, and was successfully uploaded.<br><br>";
} else {
$text="Possible file upload attack!<br><br>";
}
$img = $_FILES['userfile']['name'];
I tried to change the value of $img to both $picname and $uploadfile and it still won't work!