Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP File Upload (Windows Platform)

Status
Not open for further replies.

jollydonkey

Technical User
Sep 5, 2008
23
CA
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.


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";
 
a few things:

1. why not have a look at what the value of $_FILES['field']['error'] actually is? this will tell you what is going wrong.

2. the $upload_path probably will not work the way you think. you either need to escape the backslash or use a forward slash instead.
 
As jpadie said, your $upload_path is certainly not correct. In addition to the possible issue with slashes, it looks like $upload_path is a directory. However, the move_uploaded_file() documentation says that the destination should be a full path (directory and file name). So if you already have a D:\Files\Upload directory, then it's going to fail.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top