Need help with upload script

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

Post Reply
User avatar
devilduckie
Forum Newbie
Posts: 9
Joined: Thu Sep 14, 2006 3:37 pm

Need help with upload script

Post by devilduckie »

I'm trying to write a script that will allow users to upload files on the server, but i get an error mesage that I can't solve the problem for.

The code looks like this:

Code: Select all

result = move_uploaded_file($_FILES['uploadFile']['tmp_name'], "/home/uploads/{$_FILES['uploadFile']['name']}");
The form looks like this:

Code: Select all

<form action="scripts/laddaupp.php" method="post" name="upload" id="upload" enctype="multipart/form-data">
	<input type="file" name="uploadFile" /><br />
	<input type="submit" name="ok" value="Ladda upp"/>
</form>
When I run the script I get this error message:
Warning: move_uploaded_file(../uploads/lecture13.pdf): failed to open stream: Permission denied in /home/emergosim/scripts/laddaupp.php on line 15

Warning: move_uploaded_file(): Unable to move '/tmp/phpV2TW34' to '../uploads/lecture13.pdf' in /home/emergosim/scripts/laddaupp.php on line 15
The messages indicate that the file was uploaded into the tmp-folder but the script fails to move it because of permission problems. I've tried setting all the necessary files and folder permissions to 777 through the FTP-software, but still the same result.

SOMEONE HELP ME PLEASE!!!
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: Need help with upload script

Post by jayshields »

devilduckie wrote:

Code: Select all

result = move_uploaded_file($_FILES['uploadFile']['tmp_name'], "/home/uploads/{$_FILES['uploadFile']['name']}");
Change that.

Don't start with a forward slash in the directory to move to.

If you're upload script is in your webroot, eg. http://www.domain.com and the home directory is in http://www.domain.com/home/ then you need to lose the starting forward slash - this indicates the server root.
User avatar
devilduckie
Forum Newbie
Posts: 9
Joined: Thu Sep 14, 2006 3:37 pm

Post by devilduckie »

That did the trick. Thanks a lot for the help.
Post Reply