You can use something like this in a plug-in, sets headers. Works for pdf anyway.
$path = "path to file";
if(!file_exists($path))
throw new exception("File does not exist");
header("Content-type: File MIME type");
header("Content-disposition: attachment; filename=\"Name of the file\"");
header('Content-Transfer-Encoding: binary');
header("Content-length: " . filesize($path));
header('Expires: 0');
// check for IE only headers
if (isset($_SERVER['HTTP_USER_AGENT']) && (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
{
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
} else {
header('Pragma: no-cache');
}
readfile($path);
Thanks for your reply. How will be its html codes ? Please write a example
Thinking about it there most probably is a plug-in in the word-press plug-in repo that already does this. Look for ‘file download’ or related terms.
If you don’t already, I’d recommend learning some PHP. You would need to create a custom plugin, which serves images from php from a url like /image?id=the_image_id. The above code tells the browser to download the file by setting it as an attachment.
You need to take care doing this as it can easily create a security hole. The application I took the code from will only serve a limited number of files defined in a database. Without care, a script like this could allow someone to download any file php has access to, like your wordpress config.
Because of security issues, this is not a good project to learn PHP with. As Robert suggested, you should be able to find a plugin – no coding knowledge required for that!
If by chance you can’t find anything that works for you, consider hiring someone that knows what they’re doing at jobs.wordpress.net