简体   繁体   中英

PHP file download instead of execution - WAMP Server

I am using WAMP server to run my PHP scripts. I created a test folder in WWW folder and trying to execute PHP script using HTML form action. But instead of execution, Its downloading the PHP file. What can be the possible reason?

Apache 2.4.9 PHP 5.5.12

<!DOCTYPE html>
<html>
<body>

<form enctype="multipart/form-data" action="uploader.php" method="POST">
  <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
  Choose a file to upload: <input name="uploadedfile" type="file" /><br />
  <input type="submit" value="Upload File" />
</form>

</body>
</html>

PHP Script ( uploader.php)

<?php
 phpinfo();
?>

If you took the files from a cPanel-hosted site, check the .htaccess file in the web root folder of the files and make sure you disable this (could be similar, like php56, php71, etc):

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

like so:

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php72” package as the default “PHP” programming language.
#<IfModule mime_module>
#  AddHandler application/x-httpd-ea-php72 .php .php7 .phtml
#</IfModule>
# php -- END cPanel-generated handler, do not edit

In my case, the problem was caused because the .htaccess file had this directive to run php 7 in the Joomla's directory (Old server allowed to use different PHP versions on different directories):

<IfModule mime_module>
  AddType application/x-httpd-ea-php70 .php .php7 .phtml
</IfModule>

I Just comment them out in the new server and it worked.

Can you submit your httpd.conf here? You can also try to add the following code to your httpd.conf file and restart WAMP

AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php .php3

AddHandler application/x-httpd-php .php .phtml
AddHandler x-httpd-php .php .phtml

One of the reason can be turned off "file_uploads" in your php.ini file. So go to your php.ini file and check if you have file_uploads = On

In my case, I have to delete .htaccess file to make it work.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM