Uploading file does not work for me!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

dauzy
Forum Newbie
Posts: 11
Joined: Wed Jul 16, 2008 4:38 pm

Uploading file does not work for me!!!

Post 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!
Last edited by dauzy on Tue Sep 02, 2008 2:28 pm, edited 2 times in total.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Uploading file does not work for me!!!

Post 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
Last edited by andyhoneycutt on Tue Sep 02, 2008 2:30 pm, edited 1 time in total.
dauzy
Forum Newbie
Posts: 11
Joined: Wed Jul 16, 2008 4:38 pm

Re: Uploading file does not work for me!!!

Post 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
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Uploading file does not work for me!!!

Post 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
dauzy
Forum Newbie
Posts: 11
Joined: Wed Jul 16, 2008 4:38 pm

Re: Uploading file does not work for me!!!

Post by dauzy »

ya i did lol

i changed it from 'userfile' to 'uploadedfile' to accommodate the html form....

good catch..

thanks,
jon
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Uploading file does not work for me!!!

Post 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
        )
 
)
 
dauzy
Forum Newbie
Posts: 11
Joined: Wed Jul 16, 2008 4:38 pm

Re: Uploading file does not work for me!!!

Post 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
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Uploading file does not work for me!!!

Post 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.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Uploading file does not work for me!!!

Post 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.
dauzy
Forum Newbie
Posts: 11
Joined: Wed Jul 16, 2008 4:38 pm

Re: Uploading file does not work for me!!!

Post 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.
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Uploading file does not work for me!!!

Post 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
dauzy
Forum Newbie
Posts: 11
Joined: Wed Jul 16, 2008 4:38 pm

Re: Uploading file does not work for me!!!

Post by dauzy »

do any need to make it in any specific area?
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Uploading file does not work for me!!!

Post by andyhoneycutt »

forward slash "/" represents root of the filesystem. So, you're making a directory called "tmp" under "/".
dauzy
Forum Newbie
Posts: 11
Joined: Wed Jul 16, 2008 4:38 pm

Re: Uploading file does not work for me!!!

Post by dauzy »

thanks you for the knowledge =) it is greatly appreciated
User avatar
andyhoneycutt
Forum Contributor
Posts: 468
Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls

Re: Uploading file does not work for me!!!

Post 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
Post Reply