Page 1 of 2
Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:25 pm
by dauzy
Hey guys need some help trying to make my page able to upload files....What I've done is copied and pasted the move_uploaded_file code onto a blank page and make my own form to call the function... yet it still doesn't work... here's my code.. thanks for the help....
html code
Code: Select all
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
and here's the php code
Code: Select all
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = '/uploads/';
$uploadfile = $uploaddir . basename($_FILES['uploadedfile']['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $uploadfile)) {
echo "File is valid, and was successfully uploaded.\n";
} else {
echo "Possible file upload attack!\n";
}
echo 'Here is some more debugging info:';
print_r($_FILES);
print "</pre>";
?>
and here is what i get when i run the code...
Possible file upload attack!
Here is some more debugging info:Array
(
[uploadedfile] => Array
(
[name] => logo_larry.gif
[type] =>
[tmp_name] =>
[error] => 6
[size] => 0
)
)
thanks again for the help!
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:27 pm
by andyhoneycutt
ETA: You're actually referencing the wrong $_FILES argument. You're looking for userfile when you should be looking for uploadedfile as your FILES form suggests.
Are you sure you have write permissions to upload the file?
-Andy
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:30 pm
by dauzy
I should have permissions to uplod the file...
i did the chmod 777 on:
-file that is being uploaded
-folder that file is being uploaded to
is there anything else that i need to give permissions too??
thanks
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:33 pm
by andyhoneycutt
Now your code looks fine. Let me copy it and see if it runs on my server. Did you change your code block by chance or was I seeing things?
-Andy
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:36 pm
by dauzy
ya i did lol
i changed it from 'userfile' to 'uploadedfile' to accommodate the html form....
good catch..
thanks,
jon
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:37 pm
by andyhoneycutt
ETA: Good deal, glad I could catch that.
This code ran fine on my end. I would double-check permissions. Here's my output:
Code: Select all
File is valid, and was successfully uploaded.
Here is some more debugging info:Array
(
[uploadedfile] => Array
(
[name] => blah.png
[type] => image/png
[tmp_name] => /tmp/phpTCI37b
[error] => 0
[size] => 30401
)
)
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:39 pm
by dauzy
anything thing else you think i should check the permissions on??
so far i chmod 777
-file to be uploaded
-folder that file is getting uploaded too
thanks
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:44 pm
by andyhoneycutt
If it's still not working, I would suggest that perhaps you aren't able to write to the /tmp directory based on what your $_FILES shows up as in a print_r. It's not even being assigned a tmp name. If you have root access, I would make sure that /tmp is open to writing by PHP/Apache, although I've never run into that before I would suggest it's a possibility.
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:46 pm
by andyhoneycutt
Looking up your error message on php.net yields the following:
UPLOAD_ERR_NO_TMP_DIR
Value: 6; Missing a temporary folder. Introduced in PHP 4.3.10 and PHP 5.0.3.
This would happen either if you don't have write access to /tmp, or if (much less likely) there is no /tmp.
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:47 pm
by dauzy
ya i just found out about the tmp folder thing...
how can i create one? im on a mac if that means anythign.
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:49 pm
by andyhoneycutt
dauzy wrote:ya i just found out about the tmp folder thing...
how can i create one? im on a mac if that means anythign.
sudo mkdir /tmp;
sudo chmod -R 777 /tmp
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:50 pm
by dauzy
do any need to make it in any specific area?
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:52 pm
by andyhoneycutt
forward slash "/" represents root of the filesystem. So, you're making a directory called "tmp" under "/".
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:52 pm
by dauzy
thanks you for the knowledge =) it is greatly appreciated
Re: Uploading file does not work for me!!!
Posted: Tue Sep 02, 2008 2:54 pm
by andyhoneycutt
No problem. As an aside, I thought os x had a /tmp directory already? The machine I'm working on does, and so does our x-serve running a modified version of the same OS i'm running....Weird.
-Andy