fheleno
asked on
Upload file.Permission denied
Hi ,
I get this error message when using a HMTL/php scripts for uploading a file:
/home/fheleno1/public_html /uploads/P hueqG88mpo fkIM0nOd
Warning: move_uploaded_file(/home/f heleno1/pu blic_html/ uploads/Ph ueqG88mpof kIM0nOd/pa rte2.htm) [function.move-uploaded-fi le]: failed to open stream: Permission denied in /home/fheleno1/public_html /teste/Env iarficheir o.php on line 74
Warning: move_uploaded_file() [function.move-uploaded-fi le]: Unable to move '/tmp/phpOzQC3m' to '/home/fheleno1/public_htm l/uploads/ PhueqG88mp ofkIM0nOd/ parte2.htm ' in /home/fheleno1/public_html /teste/Env iarficheir o.php on line 74
erro
This is the relevant part of PHP script:
$dbh="fheleno1_ficheiro";
$ligacao=mysql_connect ("localhost", "fheleno1_fheleno", "+antunes1*") or die ('Não posso conectar á base de dados porque: ' . mysql_error());
mysql_select_db ("fheleno1_ficheiro");
$num=rand(1,20);
//$num=4;
echo $num;
$sql= "SELECT * FROM ficheiro WHERE num = '$num' ";
//echo rand( 1,20);
$resultado=mysql_query($sq l,$ligacao ) or die(mysql_error());
while ($row = mysql_fetch_array($resulta do)){
$codigo=$row['codigo'];
$directoria=$row['director ia'];
}
//$directoria=substr($dire ctoria, 1);
//if(substr($directoria,0, 1) eq " "){
$directoria=substr($direct oria,1);
;
//sleep (5);
$upload= '/home/fheleno1/public_htm l/uploads/ '.$directo ria;
print $upload;
$uploads_dir = $upload;
$tmp_name = $_FILES['F1']['tmp_name'];
$name = $_FILES['F1']['name'];
if (!move_uploaded_file($tmp_ name, $uploads_dir."/".$name)){
echo "erro";
}
TIP: if I force $num = 4 instead of randon or other value the script will work.
To run the complete script please use Http://tra-tec.com
Please help
Best regards
Fernando
I get this error message when using a HMTL/php scripts for uploading a file:
/home/fheleno1/public_html
Warning: move_uploaded_file(/home/f
Warning: move_uploaded_file() [function.move-uploaded-fi
erro
This is the relevant part of PHP script:
$dbh="fheleno1_ficheiro";
$ligacao=mysql_connect ("localhost", "fheleno1_fheleno", "+antunes1*") or die ('Não posso conectar á base de dados porque: ' . mysql_error());
mysql_select_db ("fheleno1_ficheiro");
$num=rand(1,20);
//$num=4;
echo $num;
$sql= "SELECT * FROM ficheiro WHERE num = '$num' ";
//echo rand( 1,20);
$resultado=mysql_query($sq
while ($row = mysql_fetch_array($resulta
$codigo=$row['codigo'];
$directoria=$row['director
}
//$directoria=substr($dire
//if(substr($directoria,0,
$directoria=substr($direct
;
//sleep (5);
$upload= '/home/fheleno1/public_htm
print $upload;
$uploads_dir = $upload;
$tmp_name = $_FILES['F1']['tmp_name'];
$name = $_FILES['F1']['name'];
if (!move_uploaded_file($tmp_
echo "erro";
}
TIP: if I force $num = 4 instead of randon or other value the script will work.
To run the complete script please use Http://tra-tec.com
Please help
Best regards
Fernando
Check the permissions on the directory where you are trying to save the file. You are fetching a record from database based upon $num. So name of folder for value '4' and other values will be different. Check the difference in the value of 'directoria' for record with $num = 4 and for any other value. Also compare the permissions.
Hey,
As devlab2012 mentioned you need to check the permissions of the directory you are uploading to, and possibly the parent directory. Is the directory you are uploading to being created on the fly? If so you may need to chmod it before uploading to it
ie:
// Everything for owner, read and execute for others
chmod($upload, 0755);
//continue upload process...
Hope that helps,
Michael.
As devlab2012 mentioned you need to check the permissions of the directory you are uploading to, and possibly the parent directory. Is the directory you are uploading to being created on the fly? If so you may need to chmod it before uploading to it
ie:
// Everything for owner, read and execute for others
chmod($upload, 0755);
//continue upload process...
Hope that helps,
Michael.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.