HTTP Error 500.50 after upload a file in laravel on IIS

3

I make a file upload in php/laravel. The files go into public/uploads directory.

But, if I access the file on the url testlocal/site/public/uploads/files.pdf, I receive this error:

HTTP-Error 500.50 - URL Rewrite Module Error.

But, if I copy this file from normal windows explorer, to the public/uploads directory, it works :|

My webconfig

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
      <rewrite>
          <rules>
              <rule name="Imported Rule 1" stopProcessing="true">
                  <match url="^" ignoreCase="false" />
                  <conditions logicalGrouping="MatchAll">
                      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                      <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                  </conditions>
                  <action type="Rewrite" url="index.php" />
              </rule>
          </rules>
      </rewrite>
  </system.webServer>

And my file upload

if (Input::hasFile('file')) {

    $file = Input::file("file");
    $size = $file->getSize();

    $originalName = $file->getClientOriginalName();
    $fileName = time() . "-" . str_random(5);
    $extension = $file->getClientOriginalExtension();

    if($file->move(__DIR__ . '/../../../public/uploads/', $fileName . "." . $extension)) {
      $upload = new Upload();
      // ...
      $upload->save();

      $answer = array( 'answer' => 'File transfer completed' );
      $json = json_encode( $answer );

      echo $json;
    }

Error Code: 0x80070005

// Edit: Ok, if i give them file everyone access, it works...but how can i make this automatic?

php
laravel
iis
upload
asked on Stack Overflow Apr 20, 2015 by nutzt • edited Jan 9, 2017 by Tiffany

1 Answer

0

A better and more robust way to get the job done is to create a brand new folder for PHP to use instead of C:\Windows\Temp . If you learned the lesson, you already know that you should avoid putting it into a system-controlled folder in order to avoid any unwanted inheritances. Just create something like C:\php\upload_dir\ and just add the IUSR and IIS_IUSRS permissions you need. Also remember to change the php.ini file accordingly.

ref: https://www.ryadel.com/en/php-how-to-fix-error-500-on-uploaded-images-and-files/

answered on Stack Overflow Jun 26, 2019 by Metalik

User contributions licensed under CC BY-SA 3.0