Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

disable downloading of the PHP files

In my server I want to show the list of the php files available in a folder. But I don't want to let my users to copy or save them, just be able to open the PHP file.

like image 398
Soheil Avatar asked Feb 03 '26 13:02

Soheil


2 Answers

You can list all files in a specific directory using glob().

//here, I will grab all PHP file names, and throw them into a assoc array:
$fileArr = glob('path/*.php');

foreach($fileArr as $val)
{

echo $val."<br>";

}

//now you have all your file names listed

To prevent users making http requests to them, you use htaccess:

Make a .htaccess file in the directory your files are sitting in and paste this into it:

deny from all

Now, no one can make http requests to files in that directory.

Why you want to do this though, is anyone's guess.

Unless you mean "open" as in execute, you should realize that as far as the web server is concerned, it is utterly impossible to figure out a user's intent. It's not as if the browser will fetch a file and say "this is for saving" and "this is for executing".

This means that one way or another, the user HAS to download the file, regardless of what they're going to end up using the file for.

like image 37
Marc B Avatar answered Feb 06 '26 01:02

Marc B