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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With