DigitalOcean home. Community Control Panel. Hacktoberfest Contribute to Open Source. Posted July 18, I set cgi. Add a comment. Subscribe Subscribed. I had same issue. Anyone can help us? Use for our example the following download URL:. With the following example, I will use a string to receive the name of a file which is stored inside a secure MySQL database.
Let say, we have a simple database table with only two columns for the ID and the filename. The code for the file download. In the first example I used the file name inside the download URL. If you really need to protect your downloads , you need to deny the direct access of the file location using Apache directives or. Use more secure slugs to receive a file name from your database. For example you can encrypt the database row key as well. Published in: PHP Scripts.
Most JavaScript examples…. I ditched Apache so many years ago… I thought it was practically shipped with nowadays. I have been banging my head for 2 days now. The issue is that the index. I'm using Ubuntu I have added the index. Sometimes it can be as simple as clearing the browser cache. If there was some misconfiguration and it was indeed downloading files, after fixing the config the browser needs to be told to stop using the cached download.
Check the version of fpm php-mysql installed on the server and php-fpm. If you are using c-panel and you changed the PHP version for the site Then c-panel will create a. Ubuntu Community Ask! Sign up to join this community.
The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. The phpinfo command worked, so I knew php was otherwise working.
The log generated no errors. Viewing the page source showed me the actual php code. This worked. I got this kind of problem. This is how I solve it. Different type of PHP versions installed to my computer. Then I remove some PHP packages from my previous list, using apt-get purge.
For people who have found this post from Google almost 6 years in the future and beyond! Another possible cause of this problem could be that you are trying to run the script in a "user directory" from the the UserDir module.
Running PHP scripts in user directories is disabled by default. You must comment or delete the tag block at the bottom that reads. Stack Overflow for Teams — Collaborate and share knowledge with a private group.
Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Apache is downloading php files instead of displaying them Ask Question. Asked 8 years, 3 months ago. Active 1 year ago. Viewed k times. OS and server information: CentOS 6. Thank you. EDIT: I have these lines in the php. Anthony Gainor. Anthony Gainor Anthony Gainor 1, 2 2 gold badges 9 9 silver badges 9 9 bronze badges. Well, how did you install it? Which SAPI? Your php module is not running. I edited the questions.
The modules do exits and they are being loaded apparently — Anthony Gainor. Did you restart apache after installation?
In the same way, when you click on PDF and TEXT file links, the content of the file will be opened in the browser without downloading the file. The solution to this problem is to download the file forcibly using the built-in PHP readfile function.
The readfile function is used in PHP script to forcibly download any file of the current location, or the file with the file path. The syntax of this function is given below. This function can take three arguments.
The first argument is mandatory, and the other two arguments are optional. This function returns the number of bytes read from the file mentioned in the first argument. The uses of this function are shown in the following two examples.
0コメント