Solved

Upload file.Permission denied

Posted on 2011-02-26
3
308 Views
Last Modified: 2013-12-13
Hi ,
I get this error message when using a HMTL/php scripts for uploading a file:

/home/fheleno1/public_html/uploads/PhueqG88mpofkIM0nOd
Warning: move_uploaded_file(/home/fheleno1/public_html/uploads/PhueqG88mpofkIM0nOd/parte2.htm) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/fheleno1/public_html/teste/Enviarficheiro.php on line 74

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpOzQC3m' to '/home/fheleno1/public_html/uploads/PhueqG88mpofkIM0nOd/parte2.htm' in /home/fheleno1/public_html/teste/Enviarficheiro.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($sql,$ligacao) or die(mysql_error());
 while ($row = mysql_fetch_array($resultado)){
$codigo=$row['codigo'];
$directoria=$row['directoria'];
  }
  //$directoria=substr($directoria, 1);
  //if(substr($directoria,0,1) eq " "){
  $directoria=substr($directoria,1);
  ;
  //sleep (5);

 $upload= '/home/fheleno1/public_html/uploads/'.$directoria;

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

0
Comment
Question by:fheleno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 13

Expert Comment

by:devlab2012
ID: 34988209
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.
0
 
LVL 5

Expert Comment

by:MichaelT_
ID: 34991164
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.
0
 
LVL 1

Accepted Solution

by:
lamzaks earned 125 total points
ID: 34995875
better do chmod(777) to upload directory with your FTP client
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question