I have a code , it works, i saved it with download.php , but i don't know, how to download the image file named simpletext.jpg present on the same root of the above mentioned file, I will be very thankful to you if you write the actual path, how to do that, the code is below....
$file_name = "a.txt";
// extracting the extension:
$ext = substr($file_name, strpos($file_name,'.')+1);
header('Content-disposition: attachment; filename='.$file_name);
if(strtolower($ext) == "txt")
{
header('Content-type: text/plain'); // works for txt only
}
else
{
header('Content-type: application/'.$ext); // works for all extensions
except txt
}
readfile($decrypted_file_path);
<a href="localhost:8888/files/download.jpg" download>Click here to download the file</a>
substitute the href with your file path..
hope this helps
<a href="/path/file_name.jpg" download="download_file_name">download</a>
download_file_name将替换file_name
You can use the htaccess file to force downloads for image files. See this similar question:
Using Htaccess to force downloads [ Forcing a download using <filesMatch> in htaccess at WWW root
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.