can anyone help me? i want to protect my file's url with PHP but i don't know how to do that can u share php code to do that? i'm vietnamese,so my english not good
Pray for world
Started on the old forum in December 2011 · view the original in the archive · old links redirect here
can anyone help me? i want to protect my file's url with PHP but i don't know how to do that can u share php code to do that? i'm vietnamese,so my english not good
Pray for world
can you be more specific with example? its too complicated to understand. do u want to protect ur files from direct download? or u wanna hide ur files url with another.. in first case you can use hotlink protection and in second case you can use mod_rewrite on .htaccess.
yoblooc295 wrote: can anyone help me?
i want to protect my file's url with PHP but i don't know how to do that can u share php code to do that? i'm vietnamese,so my english not good
$file_url = 'http://some_site.com/pathe/file.jpg';
$contents = file_get_contents($file_url);
echo $contents;
you will also need to send correct headers.
if the file is located on your site i would recommend to use
echo readfile($file_path);
or you can also use rewrite rules in you htaccess
Advertise your mobile site for FREE with AdTwirl
Gumslone's question is right... the best way is to put the file out side the folder where it can be executed eg. public_html ,using the correct headers,use echo readfile($file_path); as Gumslone said....
gumslone right you can protect your files using fread with correct header type to make it downloadable
$file_url = 'http://some_site.com/pathe/file.jpg'; $contents = file_get_contents($file_url); echo $contents;you will also need to send correct headers.
if the file is located on your site i would recommend to use
echo readfile($file_path);or you can also use rewrite rules in you htaccess
Something else to mention 😛 don't use $_GET['file']; in a
echo readfile($file_path);
function because someone else can download your site files // via modified url ..
for example if someone requests connectdb.php via your link like download.php?file=connectdb.php it will download your file .. now depends on the header you use to save the files ..
ex:
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
you could select the path from an database .. example:
$file =mysql_query("SELECT * FROM table WHERE fileid='".$myid"'.");
readfile($file['path']);
This is ten percent luck, twenty percent skill Fifteen percent concentrated power of will Five percent pleasure, fifty percent pain 😂And a hundred percent reason to remember the name!
@ just_m3 its true,again if possible,U can check the ip for double request to prevent data copiers and bot copiers from wasting ur bandwith for their benefits....