httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "kartikay malhotra" <kartikay.malho...@gmail.com>
Subject [users@httpd] Upload files to local directory
Date Wed, 17 May 2006 14:05:15 GMT
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

Mime
View raw message