PDA

View Full Version : [function.move-uploaded-file]: failed to open stream: Permission denied in


uamusa
March 7th, 2007, 05:39 PM
Trying to implement and Upload form on my Web Server:

upload.hmtl :

<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>

upload.php :
<?php
$currentdir = getcwd();

$target = $currentdir . "/upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
echo "Temp Location: $target_path<br>";
$temploc=$_FILES['uploadedfile']['tmp_name'];
echo "Temploc: $temploc<br>";

$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) //THIS IS LINE 43
{
echo "The file ".
basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>


What you get when you attempt to use the upload form :

Warning: move_uploaded_file(/home/chris/public_html/upload/Caleb.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/chris/public_html/upload.php on line 43

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpoWCXpD' to '/home/chris/public_html/upload/Caleb.jpg' in /home/chris/public_html/upload.php on line 43
Sorry, there was a problem uploading your file.




Any ideas????

JamieC
March 7th, 2007, 05:44 PM
Do you have the correct permissions on /home/chris/public_html/upload/?

uamusa
March 7th, 2007, 05:54 PM
Ok....talk about feeling like a complete moron. In past years I'd built up such a mental block regarding Linux.....and that's been my biggest problem in learning it.......I keep trying to make things more difficult than they really are. Thank You!

russellnation
January 3rd, 2008, 06:58 AM
thanx, is this a problem on .. say godaddy's hosting.

NICKKKKK
May 8th, 2008, 11:41 AM
Hello,

what exactly are the permissions for that? My folder has 777 permissions and although it works fine locally, it does not work on the host server :(

thanks
Nick

bolunmez
October 10th, 2008, 11:58 AM
Trying to implement and Upload form on my Web Server:

upload.hmtl :

<form enctype="multipart/form-data" action="upload.php" method="POST">
Please choose a file: <input name="uploaded" type="file" /><br />
<input type="submit" value="Upload" />
</form>

upload.php :
<?php
$currentdir = getcwd();

$target = $currentdir . "/upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
echo "Temp Location: $target_path<br>";
$temploc=$_FILES['uploadedfile']['tmp_name'];
echo "Temploc: $temploc<br>";

$ok=1;

//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}

//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}

//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) //THIS IS LINE 43
{
echo "The file ".
basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>


What you get when you attempt to use the upload form :

Warning: move_uploaded_file(/home/chris/public_html/upload/Caleb.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/chris/public_html/upload.php on line 43

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpoWCXpD' to '/home/chris/public_html/upload/Caleb.jpg' in /home/chris/public_html/upload.php on line 43
Sorry, there was a problem uploading your file.




Any ideas????

did you solve that ?? I 'm working to understand php at w3schools. when i tried thisexample (http://www.w3schools.com/php/php_file_upload.asp), i took similar message as yours which you seeing below:

Warning: move_uploaded_file(transpix.gif) [function.move-uploaded-file]: failed to open stream: Permission denied in /var/www/yeni/index.php on line 234

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpNwcYNk' to 'transpix.gif' in /var/www/yeni/index.php on line 234
Stored in: transpix.gif


/var/www/yeni directory and sub directories are chmod 777.:confused: