Need Help - File Upload 500 Error

I’ve been stuck on this for about a week and I just seem to be going around in circles.

The problem is receiving a 500 Internal Server error when uploading files. I’ve posted around a few forums but help is extremely limited due to me running a Windows Server.

So what have I done so far?

  1. Checked, double checked, triple checked the PHP.INI file to make sure I have all the correct attributes set:
max_execution_time 600 max_input_time 600 memory_limit 128M post_max_size 50M upload_max_filesize 50M
  1. Checked over the script and decided to test a few different scripts from various sources W3Schools, PHP.net etc same problem.

  2. Upgraded PHP5 to PHP5.3 same issue

  3. Tried to implement it using the JQuery_File_Upload API and I got unstable results. Rarely it would upload >10MB files and almost always threw out a Internal Server Error

  4. Checked the error log. I checked it but nothing out of the ordinary in there and last write was a few days ago so I added a custom log and again, nothing being written to it.

What else can I do? I’m running a dedicated server, Windows 2008, Plesk.

Please help!

Thanks.

This may be a mute point but since you didn’t mention it in your post, do you have file_uploads = On in your php.ini? Post your code so we can take a look.

Thanks for your reply.

File uploads are on. It’s a tricky one, uploading <10MB works fine.

After a little more digging around, I found a few more areas of interest:

  1. Configuration File is in C:\Windows but the loaded INI is D:\Plesk\Additional\PHP5 I don’t see an option to change this though, so I edited the INI file in C:\Windows

  2. Uploading from the webpage crashes out with the 500 error but uploading from remote connection on the webpage on the server it works fine no errors at all leading me to believe it’s not the INI file.

I’m using the JQuery_File_Upload API but I’ve tried other scripts, basic scripts, my own scripts. I just can’t seem to work it out and with it being a Windows server, support appears to be limited and it’s a dedicated server so there’s no support that side either.

Yeah the windows server may be your downfall here. I use WAMP on my laptop but I honestly don’t know if that is comparable to a hosted windows server setup. If you aren’t a member on the dynamicdrive forums I would suggest trying your question there. They have a couple pretty knowledgeable people on there that are willing to help if you provide them the info they request.

I’ve tried IIS forum, DigitalPoint, SitePoint, StackOverflow it appears only me in the world has this problem lol!

Question: what do you do with the file once it is uploaded? I think PHP runs into the execution timeout or runs out of memory. One or the other.

The execution time is 600 seconds (10 mins) the script fails once the file is uploaded at around 2 mins. The JQuery handles the upload once it’s uploaded, and I’m not overly familiar with JQuery so I decided to go to back to the stone age and use a very basic script:

[php]<?php

$allowedExts = array(“gif”, “jpeg”, “jpg”, “png”, “pdf”);
$extension = end(explode(".", $_FILES[“file”][“name”]));
if ((($_FILES[“file”][“type”] == “image/gif”)
|| ($_FILES[“file”][“type”] == “image/jpeg”)
|| ($_FILES[“file”][“type”] == “application/pdf”)
|| ($_FILES[“file”][“type”] == “image/jpg”)
|| ($_FILES[“file”][“type”] == “image/pjpeg”)
|| ($_FILES[“file”][“type”] == “image/x-png”)
|| ($_FILES[“file”][“type”] == “image/png”))
&& ($_FILES[“file”][“size”] < 9999999999)
&& in_array($extension, $allowedExts))
{
if ($_FILES[“file”][“error”] > 0)
{
echo "Return Code: " . $_FILES[“file”][“error”] . “
”;
}
else
{
echo "Upload: " . $_FILES[“file”][“name”] . “
”;
echo "Type: " . $_FILES[“file”][“type”] . “
”;
echo “Size: " . ($_FILES[“file”][“size”] / 1024) . " kB
”;
echo "Temp file: " . $_FILES[“file”][“tmp_name”] . “
”;

if (file_exists("upload/" . $_FILES["file"]["name"]))
  {
  echo $_FILES["file"]["name"] . " already exists. ";
  }
else
  {
  move_uploaded_file($_FILES["file"]["tmp_name"],
  "upload/" . $_FILES["file"]["name"]);
  echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
  }
}

}
else
{
echo “Invalid file”;
}
?>[/php]

I’ve tried about 10 different scripts, all fail 500. In terms of memory, I did at one point allocate it 256MB but it’s generally set at 128MB so I don’t think that’s the problem.

Can you set the following:

[php]error_reporting(E_ALL);
ini_set(“display_errors”,true);[/php]

And tell me if you get anything more than just the 500? Your script looks fine, and the only thing that could throw a 500 in there is move_uploaded_file. If it fails, it’ll return an error… Which, depending on your custom error handlers, might throw a 500.

In addition to this, there is an interesting comment on the PHP doc about IIS and this specific function: http://www.php.net/manual/fr/function.move-uploaded-file.php#86332. Worth looking into.

:-\

The TEMP directory is on C:\ the website is on D:\ Please god don’t be that (no actually, please do be that!). I’ll switch it over and get back to you.

I’m still no further along with this problem. ???

What was the temp directory in the end? Is it world-writable? (If your windows box uses permissions)

Can you track down the 500 in the server logs?

It was C:\Temp moving to D:\Plesk\VHOSTS\domain.com\httpdocs\account\upload\ so I created a new folder on D:\ called Temp and changed it in the PHP INI.

Something I noticed in the INI file:

Configuration File (php.ini) Path C:\Windows
Loaded Configuration File D:\Plesk\Additional\PleskPHP5\php.ini

I can’t seem to change it from C:\Windows so I checked the permissions in the Windows/php.ini file and changed them accordingly.

Smaller files move perfectly fine, it just happens to be 10M+ files and oddly, every now and then (rarely) they get through.

Stupid question, but have you checked your IIS pool settings? I don’t have a windows box nearby so I can’t check where they are inside IIS. You’re looking for a max processing time, max transfer size and all that…inside IIS.

Thanks, I’m not entirely sure where to look. I’ve checked in Application Pools, right clicked all of them and selected advanced settings but don’t see any options related to max processing time, max transfer size.

Just to update (Yes still encountering issues, I feel like I’m going crazy lol!)

I wrote an upload script in ASP which works perfectly fine = this is a PHP issue

Also, something I figured out, when trying to upload using the servers browser it works fine!

This led me to believe it’s 1 of 2 issues:

  1. Client issue. I eradicated this by trying on a different machine, error was replicated
  2. It’s point of failure is moving the uploaded file from the temp directory to the directory I specify

Any more advise?

Sponsor our Newsletter | Privacy Policy | Terms of Service