Reputation: 2039
I am trying to do something like Facebook's "Download" Photo link when viewing an album photo. Trying to avoid opening popups. Any Javascript/jQuery/PHP method to do it? I am aware of this: http://www.jtricks.com/bits/content_disposition.html But I don't have control over the server configuration to do so. Please let me know what is the best way to achieve this.
Upvotes: 1
Views: 164
Reputation: 641
You can simply use the header function of PHP to set the Content-Disposition header, for example:
header("Content-Type: image/jpeg");
header("Content-Disposition: attachment; filename=\"".$name."\"");
header("Content-Transfer-Encoding: binary");
header("Accept-Ranges: none");
header("Content-Length: ".$length);
echo $data;
Upvotes: 3
Reputation: 7656
You don't need to access the server configuration. Just use header()—before any HTML output.
Example:
header('Content-Disposition: attachment; filename=example.pdf');
Upvotes: 1
Reputation: 91963
You can send a Content-Disposition header using PHP. No need to change the server configuration. So maybe something like this:
<?php
$file = 'folder/file.jpg';
header('Content-Disposition: attachment; filename='.basename($file));
readfile($file);
?>
Upvotes: 0