jollydonkey
Technical User
Hello,
I'm trying to use PHP to enable file uploads via a web form (one file only), however, I'm getting a File Upload Error. I'm dumbfounded.
Note, I'm using a Windows platform for PHP. Below is the code, however, it's echoing a "Upload file error" (i.e. it's not getting beyond the first if statement).
Interestingly, I'm using an identical script on a Unix server and it works. Unfortunately, I'm mandated to use a Windows platform by my company.
Any help would be greatly appreciated.
Thanks,
JD.
I'm trying to use PHP to enable file uploads via a web form (one file only), however, I'm getting a File Upload Error. I'm dumbfounded.
Note, I'm using a Windows platform for PHP. Below is the code, however, it's echoing a "Upload file error" (i.e. it's not getting beyond the first if statement).
Interestingly, I'm using an identical script on a Unix server and it works. Unfortunately, I'm mandated to use a Windows platform by my company.
Any help would be greatly appreciated.
Thanks,
JD.
Code:
//Check for valid upload
if($_FILES['image']['error'] != UPLOAD_ERR_OK) {
echo 'Upload file error';
return;
}
//Check for valid upload
if(!is_uploaded_file($_FILES['image']['tmp_name'])) {
echo 'Invalid request';
return;
}
//Sanitize the filename (See note below)
$remove_these = array(' ','`','"','\'','\\','/');
$newname = str_replace($remove_these,'',$_FILES['image']['name']);
// - Make the filename unique
$newname = time().'-'.$newname;
// Save the uploaded the file to another location
$upload_path = "D:\Files\Upload";
move_uploaded_file($_FILES['image']['tmp_name'], $upload_path);
$message = " File Upload Name: ";
$message .= "$newname";