Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trouble with move_uploaded_file

Status
Not open for further replies.

vb6novice

Programmer
Sep 23, 2002
288
US
Trying to use php to upload a file to the server.

The page to select the file to upload includes the code:

Code:
<form enctype="multipart/form-data" action="insertblog.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
<input name="userfile" type="file" />
<input type="submit" value=" Submit " />
</form>

The insertblog.php page includes the code:

Code:
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo 'The blog has been added to the Web Log Archive';
    }
    else {
	echo 'The upload was unsuccessful';
	}



When I Submit the form I get the following warnings and the file is not moved to the server.

Warning: move_uploaded_file(/home/mydomain/public_html/myfilename.htm): failed to open stream: Permission denied in /home/mydomain/public_html/insertblog.php on line 61

Warning: move_uploaded_file(): Unable to move '/var/tmp/phpwB4fBN' to '/home/mydomain/public_html/myfilename.htm' in /home/mydomain/public_html/insertblog.php on line 61


Any suggestions as to what's wrong will be appreciated.
 
I think the warning is pretty clear on this one...

The user running insertblog.php (i.e. the user your web server is running as) does not have permissions to to write the file /home/mydomain/public_html/myfilename.htm

Not knowing your OS and web server that's about all I can say on that one.

Given the paths I'll assume Linux though, which will also let me assume apache.

So... you need to give the user apache runs as write permissions in /home/mydomain/public_html

Another option would be to specify a location in your second argumen to move_uploaded_file where this use can safely write.
 
Thanks for the input, skiflyer.

The site is hosted but I think it is apache.

I don't know how to give the user write permissions. Is that something that has to be arranged with the site host?
 
Depends on your hosting setup.

Usually you'll have the ability to set it in the directories you own... but yeah, I'd check with your help desk.

I'd run a quick
Code:
$result=`whoami`; //assuming linux/unix variety
echo $result;

Script before contacting so you know what user apache is running as.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top