Thursday, August 3, 2017
Simple page to download file in PHP
Simple page to download file in PHP
Below is the code snippet in PHP which download a file from the server.
<php?
// http headers for zip downloads
$localfilename=myfileOnServer.zip;
$filename=myfilenameClient.zip;
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename="".$filename.""");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($localfilename));
ob_end_flush();
@readfile($localfilename);
?>
The above codes download the file named "myFileOnServer.zip" to the client with default save file "myfilenameClient.zip".
The above download may not work if the file "myFileOnServer.zip" is larger than the default settings in php.ini (PHP 4) or php5.ini (PHP 5). To solve this download the php.ini and php5.ini from your server and add the following lines:
Upload_max_filesize = 1500M
Max_input_time = 1000
Memory_limit = 640M
Max_execution_time = 1800
Post_max_size = 2000M
download file now
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.