Here we are providing a simple code of explaining how to make a user to download file forcefully.
Clicking a link that points to a PDF or an Image file will not cause it to download to your hard drive directly. It will only open the file in your browser. Further you can save it to your hard drive. However, zip and exe files are downloaded automatically to the hard drive by default.
download.php
index.php
HTTP header fields
The Content-Length entity-header field indicates the size of the entity-body,
in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD
method, the size of the entity-body that would have been sent had the request
been a GET.
The text/html content type is an Internet Media Type as well as a MIME content type. Using HTML in MIME messages allows the full richness of Web pages to be available in e-mail. text/plain[RFC1521] The text/plain content type is the generic subtype for plain text.
In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.
List of HTTP header fields
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
Similarly, you can force download other files formats like word doc, pdf files, etc.
Normally, you don't necessarily need to use any server side scripting language like PHP to download images, zip files, pdf documents, exe files, etc. If such kind of file is stored in a public accessible folder, you can just create a hyperlink pointing to that file, and whenever a user click on the link, browser will automatically downloads that file.
<a href="demo.jpg">Download</a>
Clicking a link that points to a PDF or an Image file will not cause it to download to your hard drive directly. It will only open the file in your browser. Further you can save it to your hard drive. However, zip and exe files are downloaded automatically to the hard drive by default.
download.php
<?PHP
function force_download($file)
{
if ((isset($file))&&(file_exists($file))) {
header("Content-length: ".filesize($file));
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="' . $file . '"');
readfile("$file");
} else {
echo "No file selected";
}
}
index.php
<?php
include('download.php');
$file = 'demo.jpg';
force_download($file);
?>
HTTP header fields
The Content-Length entity-header field indicates the size of the entity-body,
in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD
method, the size of the entity-body that would have been sent had the request
been a GET.
The text/html content type is an Internet Media Type as well as a MIME content type. Using HTML in MIME messages allows the full richness of Web pages to be available in e-mail. text/plain[RFC1521] The text/plain content type is the generic subtype for plain text.
In a regular HTTP response, the Content-Disposition response header is a header indicating if the content is expected to be displayed inline in the browser, that is, as a Web page or as part of a Web page, or as an attachment, that is downloaded and saved locally.
List of HTTP header fields
https://en.wikipedia.org/wiki/List_of_HTTP_header_fields
Similarly, you can force download other files formats like word doc, pdf files, etc.
Darjeeling escorts Service
ReplyDeleteDarjeeling escorts
Siliguri Escorts Service
Siliguri Escorts
Bangalore escorts
Bangalore escorts Service
Delhi escorts
Delhi escorts Service
Chennai Escorts
Chennai Escorts Service
KOLKATA Escorts
Escorts Service In Kolkata
Escorts Service In Kolkata
Escort Service In Kolkata
Escort In Kolkata
Escorts In Kolkata
https://norton-antivirus-support1.blogspot.com
ReplyDeletehttps://outlook-customer-support1.blogspot.com
https://kaspersky-antivirus-support.blogspot.com
https://avg-antivirus-support1.blogspot.com
https://avast-antivirus-support.blogspot.com
https://bitdefender-antivirus-support1.blogspot.com
https://hp-printer-support-1.blogspot.com
https://mcafee-antivirus-support1.blogspot.com
https://roku-support-number.blogspot.com
Thanks for sharing these type of useful information. keep it up.Digital signature for ICEGATE
ReplyDeletenice post dear massage at home in south delhi
ReplyDeletemassage spa in rohini
body to body spa in rohini
body massage in noida sector 12
body massage in east delhi
body to body spa in east delhi
body to body massage in paharganj delhi
body to body spa near me
body to body massage in hauz khas
body to body massage in new delhi railway station
spa girl near me
ReplyDeletespa in delhi with price
spa in delhi ncr
best spa in south delhi
massage at home in south delhi
russian-spa-world
massage spa near me open now
jacuzzi spa in delhi
spa in delhi open now
24 hour spa in delhi
spa in delhi with extra service
ReplyDeleterussian spa in delhi
body massage in delhi near me
24 hour spa near me
full body massage in delhi price
russian spa near me
spa in noida with extra services
best massage spa in delhi
full night spa near me
full service spa near me
spa near me with extra service
ReplyDeletefemale to male spa near me
spa in mahipalpur
spa near me open now
full body massage prices near me
massage center in delhi
best spa in delhi
best massage spa near me
massage spa in delhi
spa near me with prices
Great and useful article. Creating content regularly is very tough. Thanks you. Write more with
ReplyDeleteKbc head office whatsapp number
Lucknow Escorts
ReplyDeleteKolkata Escorts
Bangalore Escorts
Chennai Escorts
Delhi Escorts
Hyderabad Escorts
Mumbai Escorts
Nagpur Escorts
Nice your website and great information thanks.
ReplyDeleteKbc head office whatsapp number