File Upload HELP!

I am trying to do a file upload using a php file and I keep receiving errors that I don’t know how to address:

Warning: move_uploaded_file(/main/uploads/spacer.gif) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/.kasian/cmarkovitz/ on line 134


Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/home/.kasian/cmarkovitz/’ to ‘/main/uploads/spacer.gif’ in /home/.kasian/cmarkovitz/ on line 134

As you can see I set the upload_tmp_dir in my php.ini as well as allowing file uploads, etc.

I am still unable to do it…


Thanks in advance.


post the code you have around those lines if you want someone to help you.

the warnings themselves can be vague without the code.

Just to make sure. Did you remember to set the enctype parameter in the posting form that contains the “input type=file”?

The form tag itself needs: ENCTYPE=“multipart/form-data”

You probably did this, but the error messages make me think PHP can’t find the uploaded binary. Something that would happen if you forgot ENCTYPE. It’s an easy oversight.

BC Tech
Team Shocker

Below is the code that I am using:
// Address error handing.
ini_set (‘display_errors’, 1);
error_reporting (E_ALL & ~E_NOTICE);

if (isset ($_POST[‘submit’])) { // Handle form.

// Try to move the uploaded file.
if (move_uploaded_file ($_FILES[‘thefile’][‘tmp_name’], “/main/uploads/{$_FILES[‘thefile’][‘name’]}”)) {

print ‘

Your file has been uploaded.


} else { // Problem!

print '

Your file could not be uploaded because: ';

// Print a message based upon the error.
switch ($_FILES[‘thefile’][‘error’]) {
case 1:
print ‘The file exceeds the upload_max_filesize setting in php.ini’;
case 2:
print ‘The file exceeds the MAX_FILE_SIZE setting in the HTML form’;
case 3:
print ‘The file was only partially uploaded’;
case 4:
print ‘No file was uploaded’;
print ‘.


} // End of SUBMIT IF.

// Leave PHP and display the form.
// Always show the form.

// Create the form.
echo ’

Upload a file using this form:



As you can see the ENCTYPE is set to “multipart/form-data” and the input type is set to FILE.

Thanks again in advance for your help.

I posted the code and no one has replied!!!

Help…if you have better code please let me know, I will use that instead.

Thanks in advance for the help.

I’m not an expert on this stuff, but as you have no other answers as of yet, I’ll point out the one thing that looks “strange” to me:

Are you sure about the "’/main/uploads/spacer.gif’ " being a valid destination? Where does “/main” live in your directory tree? The way I’m reading it, it looks llike you are trying to write a file to a directory called “main” beneath root - which you can’t do, as you do not have write access to root.

If I’m nutso here, just ignore :wink:


Thanks rlparker…missed that, I had a variable at the top called $upload_dir and I changed that, but I hardcoded the directory at some point, and when I corrected it it works.

You’re a life saver…

Good Deal! Sometimes it just takes another set of eyes :wink: I’m glad you got it working.