Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

I'm trying to debug an issue with a WordPress 3.5.1 where I cannot upload media via HTTP at all; the media uploader simply says "HTTP error" and fails. To diagnose what's going on, I decided to write (i.e. copy from w3schools) a really basic PHP file uploader to see if there's something weird going on behind the scenes. But for some reason, the $_FILE structure doesn't contain any information at all, even in the most basic of examples:

file.php :

<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
  <label for="file">Filename:</label>
  <input type="file" name="file" id="file"><br>
  <input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

upload.php :

<?php
if ($_FILES["file"]["error"] > 0)
{
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else
{
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>

In every browser I've tried, with every file I've tried, this just outputs:

Upload: 
Type: 
Size: 0 kB
Stored in:

and printing $_FILES shows that it is just an empty array.

I'm using PHP-5 on shared hosting (lunarpages), but the php.ini file has file_uploads on and the size of the files I tried is nowhere even close to the upload_max_filesize. I am ready to throw my laptop against a wall, so any help would save me a couple thousand dollars.

share|improve this question
2  
Whats the output, when you discard the if/else and just put <?php error_reporting_(E_A‌​LL); ini_set('display_err‌​ors', true); print_r($_FILES); ?> in the script? – DanFromGermany Jun 13 '13 at 21:28
2  
Do you have write permissions to that folder? – Don Rhummy Jun 13 '13 at 21:31
1  
what has w3fools.com to do with this question? – DanFromGermany Jun 13 '13 at 21:32
2  
I copied exactly your code and it worked for me. Change the permission of everything to 777 for directories and 666 for files – DanFromGermany Jun 13 '13 at 21:40
1  
If it's hosted by Lunar, I'd give them a call. They might have set up some unusual settings. BTW, if php.ini or .htaccess or any of the relevant ".conf" files don't allow it, those ini_set commands won't do anything. – Don Rhummy Jun 13 '13 at 22:04
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
  <label for="file">Filename:</label>
  <input type="file" name="file" id="file"><br>
  <input type="submit" name="submit" value="Submit">
</form>

<?php
phpinfo();
?>

</body>
</html>

This worked for me, $_FILES was not empty, using a common Debian installation, PHP 5.2; try to adjust the permissions of your files and direcotires to 777

share|improve this answer
    
I tried adjusting the permissions to 777 for everything, but that resulted in an Internal Server Error when loading either php file. – Maxwell Collard Jun 13 '13 at 21:57
    
Only thing I can help you is, take a deep look into phpinfo(); and your hosters settings. >.< – DanFromGermany Jun 13 '13 at 22:22

I had a similar issue once with a shared host. Turned out that I had no tmp directory set, therefore nothing was being uploaded. Check with your host that your php.ini is set up correctly and that a tmp directory exists for uploads and that you have write permissions for it.

share|improve this answer
$target="Your Path";
if(move_uploaded_file($_FILES['file']['tmp_name'], $target)) 
{
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"]; 
} 
else 
{ 
  echo "Unable to move temp file to target.";
} 
share|improve this answer

If it is not yet too late, you should check your apache logs. The most probably cause is that the apache - and so your php interpreter - has no permission to your predefined upload directory.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.