RE: [users@httpd] Upload files to local directory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 root.

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 uploaded";

 

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 out….so 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 [mailto:kartikay.malhotra@xxxxxxxxx]
Sent: Wednesday, May 17, 2006 8:05 AM
To: users@xxxxxxxxxxxxxxxx
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:

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


<body>
<?php
if(isset($_POST['upload']))
{
$_FILES['userfile']['name']='/usr/share/wallpapers/Circuit.jpg';

        $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( $_FILES['uploadedfile']['name']);

         if(move_uploaded_file($tmpName, $target_path)) {
            echo "The file ". basename( $fileName). " has been uploaded";
         }
         else{
             echo "There was an error uploading the file, please try again!";
         }
}
?>

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

</html>

Sample output:

/usr/share/wallpapers/Circuit.jpg
/tmp/php8YIDF9
4376
There was an error uploading the file, please try again!

Please help!!
Many Thanks
KM


[Index of Archives]     [Open SSH Users]     [Linux ACPI]     [Linux Kernel]     [Linux Laptop]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Squid]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]

  Powered by Linux