I'm creating a form that allows visitors to upload a file to my server. To avoid issues with same name files being uploaded I'd like to automatically add the sender's lastname and date to the file name.
For example, the user enters their name of SMITH.
The form is submitted, it's uploaded but is renamed on the server.
I was thinking this might be a solution:
I'm most likely wrong so if anyone can fix this IT WOULD BE GREATLY appreciated.
$submitor = $_POST["lname"];
$filesent = $submitor . $date . basename($_FILES['Filedata']['name']);
$target_path = "uploads/";
$target_path = $target_path . basename( $_FILES['Filedata']['name']);
// If file name check is valid, move the file to $target_path
if(move_uploaded_file($_FILES['Filedata']['tmp_name'], $target_path))
{
// File has been uploaded successfully.
echo "The file ". basename( $_FILES['Filedata']['name']). " has been uploaded";
}else{
// If there is an error in uploading the file.
echo "There was an error uploading the file, please try again!";
}
?>