0
<!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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Unfortunately not, all that changes is in the output I see the full path :(
1. If the uploads is not in the root, is the directory above it writable by the web server? 2. If you allow php errors on the page does it give any more details or does apache error logs have anything in it regarding this issue?
Hmm. I tured on my php warnings, and I got two warnings on my move_uploaded_file command... failed to open stream: Permission denied in (my path)... and Unable to move '/var/tmp/phpmTaWs0' to '7230_156973410469_774774_n.jpg' in (my path)...is this a chmod problem?
Yeah, it seems to be a permission issue... is the upload directory in the root or under another directory like admin or something like that?
It's in one of my sub-directories on the schools server. I'll keep looking now that I know what the problem is. Thanks a ton.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.