How to download a file using php? -
i want download file server using php. searched google , found stackoverflow answer here. answer shows have write these codes purpose.
$file_url = 'http://www.myremoteserver.com/file.exe'; header('content-type: application/octet-stream'); header("content-transfer-encoding: binary"); header("content-disposition: attachment; filename=\"" . basename($file_url) . "\""); readfile($file_url);
but able merely these 2 lines:
header("content-disposition:attachment; filename=uploads1/efl1.5_setup.exe"); readfile("uploads1/efl1.5_setup.exe");
so why should write few more lines codes above?
header('content-type: application/octet-stream');
the content-type should whatever known be, if know it. application/octet-stream defined "arbitrary binary data" in rfc 2046, , there's definite overlap here of being appropriate entities sole intended purpose saved disk, , point on outside of "webby". or @ direction; thing 1 can safely application/octet-stream save file , hope else knows it's for.
header("content-transfer-encoding: binary");
content-transfer-encoding specifies encoding used transfer data within http protocol, raw binary or base64. (binary more compact base64. base64 having 33% overhead).
reference:
do need content-type: application/octet-stream file download?
Comments
Post a Comment