Page 1 of 1

Need help with upload script

Posted: Thu Sep 14, 2006 5:15 pm
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!!!

Re: Need help with upload script

Posted: Thu Sep 14, 2006 5:28 pm
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.

Posted: Fri Sep 15, 2006 3:38 am
by devilduckie
That did the trick. Thanks a lot for the help.