Forum Moderators: coopster
I`m using this uploader script that lets people upload stuff to my server. Only problem is it overwrites the existing file if a file with the same name is already uploaded.
Whats the best way to check if a file exists and display an error message if it does?
The script is written something like this:
if ($-POST['uploadfile'])
{
if ($file_size < $MAX_FILE_SIZE)
{
copy ($file, $site_path.$file_name);
mail("$your_email", "$email_subject", "$email_message", "From: $site_name <$your_email>\r\nReply-To: $site_name <$your_email>");
unlink($file);
}
Location("http://path/to/thanks/page.php");
exit;
}
Thank you!
You would use it like this:
if(!is_file($site_path.$file_name))
{
copy ($file, $site_path.$file_name);
mail("$your_email", "$email_subject", "$email_message", "From: $site_name <$your_email>\r\nReply-To: $site_name <$your_email>");
unlink($file);
} else {
// output some error message of your choice
}
mavherick