title: how to solve iis error 500 upload file using php
body: <p>I am trying to upload a file to an IIS based server. here is my code:</p>
  
  <pre><code>&lt;?php
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  //ini_set('error_log','/httpdocs/error_log');
  echo "upload_max_filesize: " . ini_get ("upload_max_filesize"). "&lt;br&gt;";
  echo "post_max_size: " . ini_get ("post_max_size"). "&lt;br&gt;";
  echo "memory_limit: " . ini_get ("memory_limit"). "&lt;br&gt;";
  echo "max_file_uploads: " . ini_get ("max_file_uploads"). "&lt;br&gt;";
  echo "max_execution_time: " . ini_get ("max_execution_time"). "&lt;br&gt;";
  echo "max_input_time: " . ini_get ("max_input_time"). "&lt;br&gt;";
  echo "file_uploads: " . ini_get ("file_uploads"). "&lt;br&gt;";
  echo "default_socket_timeout: " . ini_get ("default_socket_timeout"). "&lt;br&gt;";
  echo "&lt;br&gt;";
  if ($_FILES["file"]["error"] &gt; 0)
    {
    echo "Error: " . $_FILES["file"]["error"] . "&lt;br&gt;";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "&lt;br&gt;";
    echo "Type: " . $_FILES["file"]["type"] . "&lt;br&gt;";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB&lt;br&gt;";
    echo "Stored in: " . $_FILES["file"]["tmp_name"];
    }
  ?&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"
  enctype="multipart/form-data"&gt;
  &lt;label for="file"&gt;Filename:&lt;/label&gt;
  &lt;input type="file" name="file" id="file"&gt;&lt;br&gt;
  &lt;input type="submit" name="submit" value="Submit"&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I used to get this error when i try to upload a file greater than 13MB:</p>
  
  <blockquote>
    <p>Server Error</p>
    
    <p>500 - Internal server error. There is a problem with the resource you
    are looking for, and it cannot be displayed.</p>
  </blockquote>
  
  <p>then i added the error_reporting and i got this:</p>
  
  <blockquote>
    <p>Network Error (tcp_error) </p>
    
    <p>A communication error occurred: "Can't send more" The Web Server may
    be down, too busy, or experiencing other problems preventing it from
    responding to requests. You may wish to try again at a later time.</p>
    
    <p>For assistance, contact your network support team.</p>
  </blockquote>
  
  <p>this is the settings:</p>
  
  <blockquote>
    <p>upload_max_filesize: 20M </p>
    
    <p>post_max_size: 128M </p>
    
    <p>memory_limit: -1</p>
    
    <p>max_file_uploads: 20 </p>
    
    <p>max_execution_time: 50000 </p>
    
    <p>max_input_time: 50000</p>
    
    <p>file_uploads: on </p>
    
    <p>default_socket_timeout: 6000</p>
  </blockquote>
  
  <p>this is the web.config file:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;!-- 
      Note: As an alternative to hand editing this file you can use the 
      web admin tool to configure settings for your application. Use
      the Website-&gt;Asp.Net Configuration option in Visual Studio.
      A full list of settings and comments can be found in 
      machine.config.comments usually located in 
      \Windows\Microsoft.Net\Framework\vx.x\Config 
  --&gt;
  &lt;configuration&gt;
    &lt;!--
      &lt;configSections&gt;
        &lt;sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
          &lt;sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
            &lt;section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/&gt;
            &lt;sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"&gt;
              &lt;section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere" /&gt;
              &lt;section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /&gt;
              &lt;section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /&gt;
              &lt;section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication" /&gt;
            &lt;/sectionGroup&gt;
          &lt;/sectionGroup&gt;
        &lt;/sectionGroup&gt;
      &lt;/configSections&gt;  
  --&gt;
    &lt;appSettings /&gt;
    &lt;system.web&gt;
      &lt;httpRuntime 
          executionTimeout="9000" 
          maxRequestLength="65536" 
          useFullyQualifiedRedirectUrl="false" 
          minFreeThreads="8" 
          minLocalRequestFreeThreads="4" 
          appRequestQueueLimit="1000" 
          enableVersionHeader="true" 
      /&gt;
      &lt;customErrors mode="On" /&gt;
      &lt;!-- 
              Set compilation debug="true" to insert debugging 
              symbols into the compiled page. Because this 
              affects performance, set this value to true only 
              during development.
          --&gt;
      &lt;!--
              The &lt;authentication&gt; section enables configuration 
              of the security authentication mode used by 
              ASP.NET to identify an incoming user. 
          --&gt;
      &lt;authentication mode="Forms" /&gt;
      &lt;!--
              The &lt;customErrors&gt; section enables configuration 
              of what to do if/when an unhandled error occurs 
              during the execution of a request. Specifically, 
              it enables developers to configure html error pages 
              to be displayed in place of a error stack trace.
  
          &lt;customErrors mode="RemoteOnly" defaultRedirect="GenericErrorPage.htm"&gt;
              &lt;error statusCode="403" redirect="NoAccess.htm" /&gt;
              &lt;error statusCode="404" redirect="FileNotFound.htm" /&gt;
          &lt;/customErrors&gt;
          --&gt;
      &lt;pages&gt;
        &lt;controls&gt;
          &lt;add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
          &lt;add tagPrefix="asp" namespace="System.Web.UI.WebControls" assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
        &lt;/controls&gt;
      &lt;/pages&gt;
      &lt;httpHandlers&gt;
        &lt;remove verb="*" path="*.asmx" /&gt;
        &lt;add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
        &lt;add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
        &lt;add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false" /&gt;
      &lt;/httpHandlers&gt;
      &lt;httpModules&gt;
        &lt;add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &lt;/httpModules&gt;
      &lt;sessionState timeout="2880" /&gt;
    &lt;/system.web&gt;
    &lt;system.codedom&gt;
      &lt;compilers&gt;
        &lt;compiler language="c#;cs;csharp" extension=".cs" warningLevel="4" type="Microsoft.CSharp.CSharpCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
          &lt;providerOption name="CompilerVersion" value="v3.5" /&gt;
          &lt;providerOption name="WarnAsError" value="false" /&gt;
        &lt;/compiler&gt;
        &lt;compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
          &lt;providerOption name="CompilerVersion" value="v3.5" /&gt;
          &lt;providerOption name="OptionInfer" value="true" /&gt;
          &lt;providerOption name="WarnAsError" value="false" /&gt;
        &lt;/compiler&gt;
      &lt;/compilers&gt;
    &lt;/system.codedom&gt;
    &lt;!-- 
          The system.webServer section is required for running ASP.NET AJAX under Internet
          Information Services 7.0.  It is not necessary for previous version of IIS.
      --&gt;
    &lt;system.webServer&gt;
      &lt;security&gt;
          &lt;requestFiltering&gt;
             &lt;requestLimits maxAllowedContentLength="2147483648" /&gt;
          &lt;/requestFiltering&gt;
      &lt;/security&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;modules&gt;
        &lt;remove name="ScriptModule" /&gt;
        &lt;add name="ScriptModule" preCondition="managedHandler" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &lt;/modules&gt;
      &lt;handlers&gt;
        &lt;remove name="WebServiceHandlerFactory-Integrated" /&gt;
        &lt;remove name="ScriptHandlerFactory" /&gt;
        &lt;remove name="ScriptHandlerFactoryAppServices" /&gt;
        &lt;remove name="ScriptResource" /&gt;
        &lt;add name="ScriptHandlerFactory" verb="*" path="*.asmx" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
        &lt;add name="ScriptHandlerFactoryAppServices" verb="*" path="*_AppService.axd" preCondition="integratedMode" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
        &lt;add name="ScriptResource" preCondition="integratedMode" verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /&gt;
      &lt;/handlers&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding appliesTo="v2.0.50727" xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Extensions" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Extensions.Design" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="3.5.0.0" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I accessed the server remotely and tested it the response was:</p>
  
  <blockquote>
    <p>PHP Warning:  POST Content-Length of 9202605 bytes exceeds the limit
    of 8388608 bytes in Unknown on line 0</p>
  </blockquote>
  
  <p>How can i fix this problem?</p>