Saturday, April 14, 2018

How to Download Files From Server Using PHP Script

In this tutorial, we are going to discuss how to download simple image file from the server location to local machine. Using this technique you can download all kind of files, which includes image, document, zip, PDF etc. This method is followed by most of the PHP websites to perform download operations.

How to Download Files From Sever to Using PHP Script



Lets see the below simple php script, which help us to download files from server.
download-file.php
<?php
//Image file at sever loaction to download
$file = 'skp.png';

if (file_exists($file)) {
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename="'.basename($file).'"');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($file));
    readfile($file);
    exit;
}

Video Link : 


Download Link :
https://github.com/skptricks/php-Tutorials/tree/master/How%20to%20Download%20Files%20From%20Sever%20to%20Using%20PHP%20Script

This is all about PHP download file script. Thank you for reading this article, and if you have any problem, have a another better useful solution about this article, please write message in the comment section.


No comments:

Post a Comment