Help with uploading files

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

frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Help with uploading files

Post by frankpmjr »

Hi, I created a form that uploads files into my server (for CMS system) and it all seems to work well except that when after the file is uploaded, I can't find it. I used the script below to move it to what I think is the correct place but it isn't there when I check. Any insight would be appreciated

Code: Select all

move_uploaded_file($_FILESї'upload_snd']ї'tmp_name'],"..downloads/$filename");
         echo'<p>The sound file has been uploaded!</p>';
Is there anyway I can verify that the file is indeed being uploaded? I tried to navigate to the tmp_name to see if it is there but that doesn't work either.

Thanks for the help.

Frank
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

make sure that the folder you are uploading to is there, and the path is correct, try:

Code: Select all

<?php
move_uploaded_file($_FILES['upload_snd']['tmp_name'],"../downloads/$filename"); 
         echo'<p>The sound file has been uploaded!</p>';
?>
if you are not on windows, you also need to chmod the folder to 0777.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

I'm on a linux machine. I hate to sound like an idiot but can you explain chmod the folder to 0777, thanks.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[google]man chmod[/google]

[php_man]chmod[/php_man]()
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

To clarify, it is to make sure that I can write files into the folder?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

write, read, and/or execute files or folders.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I did it (code is below) but it didn't make a difference.  I still can't find the file.

Code: Select all

chmod ("../downloads", 0777);
        $extension = explode('.',$_FILES['upload_snd']['name']);
        $uid = mysql_insert_id();
        $filename = $uid.'.'.$extension[1];

           move_uploaded_file($_FILES['upload_snd']['tmp_name'],"../downloads/$filename");

feyd | Please use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

maybe you are missing something. Add

Code: Select all

error_reporting(E_ALL);
ini_set('display_errors', '1');
in front of your code.

also, check the return from

Code: Select all

move_uploaded_file[/php_man]() to make sure it's doing it okay...
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

I got a bunch of warnings but I can't seem to reply to this post with any content.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

I think they mean to check the php.ini file, how can I find that?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

IE5 on a Mac? Upgrade to a newer browser.

I don't see any other reason you wouldn't be able to post with the output.. granted, you may need to break it apart if it's really huge.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

The errors are that the file failed to open, chmod not permitted and unable to move the uploaded file out of the temp directory.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

which file failed to open?
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

No, IE on a PC. When I try to post the errors (either by cut and paste or retyping I get:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, wwwadmin@devnetwork.net and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
frankpmjr
Forum Commoner
Posts: 26
Joined: Wed Sep 15, 2004 9:13 am

Post by frankpmjr »

The file that failed to open was:
move_uploaded_file(../downloads/0.txt): failed to open
Post Reply