I have a form which uploads an image, and inserts a row into a mysql table.
The code, taken from a tutorial, makes a unique filename by adding a $now in front of it. This filename also includes the file's directory.
I'd like to get a variable to equal just the filename, without the directory.
// make a unique filename for the uploaded file and check it is
// not taken... if it is keep trying until we find a vacant one
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
$now++;
}
// now let's move the file to its final and allocate it with the new filename
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
or error('receiving directory insuffiecient permission', $uploadForm);
The way I see it, I could change $uploadFilename) to NOT include the directory, and then add it back in in the second part. Would this work? Or is there a better way?