Tools
Log in
English

Learn to codeSecurity check

PHP runs in upload folders

HighP07PHP servers (Linux and Windows)

Block PHP handling in upload folders so files people upload can never run as…

What is the risk

If PHP runs in a board or shop upload folder, one PHP file disguised as an image becomes a web shell.

File name checks are often bypassed (shell.php.jpg, mixed case and so on). Blocking execution in the folder itself is what keeps you safe.

How to check

Linux

sudo find /var/www -type d \( -name uploads -o -name upload -o -name files -o -name data \) -exec find {} -iname '*.php*' \;

Check any file it lists for a web shell first (P01).

Windows PowerShell (admin)

Get-ChildItem C:\inetpub\wwwroot -Recurse -Directory -Include uploads,upload,files,data | Get-ChildItem -Recurse -Filter *.php*

How to fix

nginx config

location ~* ^/(uploads|files|data)/.*\.php$ { deny all; }

Put it above the location ~ \.php$ block that passes to PHP. nginx checks regex locations from the top and uses the first match. Then run sudo nginx -t and sudo systemctl reload nginx.

Apache config

<Directory "/var/www/html/uploads">
    <FilesMatch "\.(php|phtml|phar)">
        Require all denied
    </FilesMatch>
</Directory>

Add it to the site config (vhost), run sudo apachectl configtest and reload. Change the folder path to your upload folder.

IIS web.config

<configuration>
  <system.webServer>
    <security>
      <requestFiltering>
        <fileExtensions>
          <add fileExtension=".php" allowed="false" />
        </fileExtensions>
      </requestFiltering>
    </security>
  </system.webServer>
</configuration>

Save as web.config inside the upload folder to block .php requests there.

How to prevent it

  • Store uploads outside the web root and serve them through PHP.
  • Let the server pick the file name (random name plus an allowed extension) instead of keeping the uploaded name.
  • Make upload folders writable but never executable.

Check again after fixing

Linux

echo '<?php echo 1;' | sudo tee /var/www/html/uploads/t.php
curl -s -o /dev/null -w '%{http_code}\n' https://example.com/uploads/t.php
sudo rm /var/www/html/uploads/t.php

403 means it is blocked. 200 means PHP still runs there. Always delete the test file.

Run the downloaded check again and make sure this item passes.

Security check home