Reputation: 1
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);
Upvotes: 0
Views: 40
Reputation: 23
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
Upvotes: 0
Reputation: 46
<a href="/path/file_name.jpg" download="download_file_name">download</a>
download_file_name will replace file_name
Upvotes: 0
Reputation: 5147
<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
Upvotes: 1