httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Billy Nab" <>
Subject RE: [users@httpd] Upload files to local directory
Date Wed, 17 May 2006 14:34:23 GMT
I do not believe this is actually an apache issue, however a few things
I noticed are:


Make sure the use PHP runs as has write access to /var/www/html
(probably not a good idea to have it in this folder, if this is your
document root, as you open up the entire web to writing by apache/php or
whatever user php runs as)

In the line:
$_FILES['userfile']['name']='/usr/share/wallpapers/Circuit.jpg'; Why are
you specifying the file name here?  Should it not come from the file
upload form?


If you read your error message you will note it is trying to upload the
/usr/share/wallpapers/Circuit.jpg file, so it is trying to read a local
file, put it in the temp folder, then move the file to the document

Also you may check yoru targetpath statement - you define the target
path, then ad the file name on it, then try to copy the file over the
file name you just defined:


        $target_path = "/var/www/html/";   //defined here

        $target_path = $target_path . basename(
$_FILES['uploadedfile']['name']);  //you add a file name here

         if(move_uploaded_file($tmpName, $target_path)) { ///here you
try to move the file with the $tmpName to the $targetPath, but
$targetPath already has the file name defined on it in the line above
            echo "The file ". basename( $fileName). " has been


Per the PHP Docs on move_uploaded_file:

"This function checks to ensure that the file designated by filename is
a valid upload file (meaning that it was uploaded via PHP's HTTP POST
upload mechanism). If the file is valid, it will be moved to the
filename given by destination."  In this case, you have attempted to
define the file using the $_FILES statement I pointed it is
not coming from the post method as it should.


If you want, I will attempt to re-write it for you and reply personally
to keep the apache thread clean....


B Nab


From: kartikay malhotra [] 
Sent: Wednesday, May 17, 2006 8:05 AM
Subject: [users@httpd] Upload files to local directory


Hi everyone!

I'm a linux user. I want to upload files to my Apache HTTP server. I
have a MySQL database in place. But prior to that I wish to save
uploaded files in a temporary folder. 

I've used PHP scripts with HTTP POST method. But to no avail. No matter
what tutorial I consult, I cannot save the uploaded file. 

1. What could I be doing wrong?

My file for reference:

<title>Upload File To MySQL Database</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">


        $fileName = $_FILES['userfile']['name'];
        $tmpName  = $_FILES['userfile']['tmp_name'];
        $fileSize = $_FILES['userfile']['size'];
        $fileType = $_FILES['userfile']['type'];

        echo $fileName;
        echo "<br>";
        echo $tmpName;
        echo "<br>";
        echo $fileSize;
        echo "<br>"; 

        $target_path = "/var/www/html/"; 

        $target_path = $target_path . basename(

         if(move_uploaded_file($tmpName, $target_path)) {
            echo "The file ". basename( $fileName). " has been
             echo "There was an error uploading the file, please try

<form action="" method="post" enctype="multipart/form-data"
  <table width="350" border="0" cellpadding="1" cellspacing="1"
      <td width="246"><input type="hidden" name="65536"
value="2000000"><input name="userfile" type="file" class="box"
      <td width="80"><input name="upload" type="submit" class="box"
id="upload" value="  Upload  "></td> 

Sample output:
There was an error uploading the file, please try again! 

Please help!!
Many Thanks

View raw message