SetSlapShot
SetSlapShot

Reputation: 1298

PHP file not handling uploads

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <title>File Manager</title>
    <link rel="stylesheet" href="css/style.css" />
  </head>
  <body>
    <div id="nav">
      <a href="index.php">View</a> | <a href="upload-file.php">Upload</a>
    </div>
<h1>File Manager &mdash; Upload Files</h1>
<form enctype="multipart/form-data" action="upload-file.php" method="post">
  <input type="hidden" name="MAX_FILE_SIZE" value="50000" />
  <p><input type="file" name="uploaded[]"/></p>
  <p><input type="file" name="uploaded[]"/></p>
  <p><input type="file" name="uploaded[]"/></p>
  <p><input type="file" name="uploaded[]"/></p>
  <p><input type="file" name="uploaded[]"/></p>
  <p><input type="submit" value="Upload" /></p>
</form>
 <?php
                           $target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name'][0]);
$tmpfil = $_FILES['uploaded']['tmp_name'][0];
$ok=1;
if(move_uploaded_file($tmpfil, $target))
  {
    echo "The file ". basename( $_FILES['uploaded']['name']). " has been upload\
ed";
  }
else {
  echo $target . " WAS TARGET<br/><br/>";
  echo $tmpfil . " WAS TEMP<br/><br/>";
  print_r($_FILES);
  echo "Sorry, there was a problem uploading your file.";
}
 ?>
  </body>
</html>

Right now I'm only trying to get the first upload one to work before I keep going, (that;s why im indexing 0), but this produces this output when i try to upload a picture

upload/puppy.jpg WAS TARGET

/var/tmp/php9raOkG WAS TEMP

Array ( [uploaded] => Array ( [name] => Array ( [0] => puppy.jpg [1] => [2] => [3] => [4] => ) [type] => Array ( [0] => image/jpeg [1] => [2] => [3] => [4] => ) [tmp_name] => Array ( [0] => /var/tmp/php9raOkG [1] => [2] => [3] => [4] => ) [error] => Array ( [0] => 0 [1] => 4 [2] => 4 [3] => 4 [4] => 4 ) [size] => Array ( [0] => 15404 [1] => 0 [2] => 0 [3] => 0 [4] => 0 ) ) ) Sorry, there was a problem uploading your file.

All of my scripts and the upload/ folder are chmoded 777 because I didn't remember what the correct permission was and I thought it should work...

Thanks in advance!

Upvotes: 0

Views: 61

Answers (1)

Greg Alexander
Greg Alexander

Reputation: 1222

Perhaps your path to the uploads directory is incorrect try full path..

$target = "/your/full/server/path/to/this/dir/upload/";

It could also be a permissions issue, turn on PHP errors or look in your apache error logs.

Upvotes: 1

Related Questions