PHP: Download file from android browser default - php

I have code download file such as:
$path = "../wap/file/{$row['file_name']}";
$filename = $row['file_name'];
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header('Content-Type: application/octetstream');
header("Content-Disposition: attachment; filename=\"$filename\"");
header('Content-Type: application/force-download');
header("Content-Type: application/save");
header("Content-Transfer-Encoding: binary");
header('Content-Description: File Transfer');
header("Content-Disposition: attachment; filename=\"{$row['file_name']}\"");
header('Content-Length: ' . filesize($path));
readfile($path);
When I download file on android by Opera, download successful. But if download file by browser default of android, download failed!

Related

Download file .ZIP with PHP automatically

I would like to download a file from a folder on my server and automatically start the download without the person seeing the original file link.
Here is my current script, but it downloads an invalid corrupted file.
$filename = "dsk.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="./zz/'.$filename.'");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize("./zz/".$filename));
ob_end_flush();
#readfile("./zz/".$filename);
Can you please help me? The file, dsk.zip, is in the folder zz.
$file = "dsk.zip"; // this is what you will get from a param (i.e. ?file=dsk.zip) or from DB query
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename='zz/'.$file");
header("Content-Length: ".filesize($file));
header("Content-Type: application/force-download");
header("Content-Transfer-Encoding: binary");
readfile('zz/'.$file);

problem with header for making zip not able to download and create

Problem with making zip file not able to create and download show only zip name in response
if (file_exists($filename)) {
header("HTTP/1.1 200 OK");
header("Pragma: public");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
$mimeType = 'application/json';
header("Content-type: " . $mimeType);
header("Content-Disposition: attachment; filename=\"{$filename}\"");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . mb_strlen($filename));
echo $filename;
flush();
readfile($filename);
// delete file
unlink($filename);
}
Try to set the Content-type like this: header("Content-type: application/zip");

PHP How to download file tar.gz using download button?

i have a code like this :
header("Pragma: public", true);
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-type: application/rar');
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header('Content-Type: application/download');
header('Content-Disposition: attachment; filename='.$fullname);
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . filesize($fullname));
$fp = fopen($fullname, "r");
fpassthru($fp);
fclose($fp);
based on above code, download is running, but the tar.gz cannot be opened.
how to solve it? is it possible to download tar.gz?
Content type for GNU zipped archive is application/x-gzip.
You should use below code to set content type
header('Content-type: application/x-gzip');

PHP download script returns download-file.php instead of filename

i wrote a download script that find a restricted file from server and after reading that, prepare the file for user to download it with the following headers.
header('Content-Type: application/octet-stream');
header("Content-Length: $filesize");
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Accept-Ranges: bytes');
header('Connection: Keep-Alive');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
but sometimes with default browsers download managers, it returns download-file.php instead of filename!
for example it should return abc.zip but it returns download-file.php and download process works perfectly
any help will be appreciated
Since I don't know how you're using $file or $filesize try this instead:
$file = "abc.zip"; // adjust accordingly
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($file));
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file));
header("Content-Description: File Transfer");
#readfile($file);
exit();
plus, a missing readfile()
This line:
header("Content-Length: $filesize");
should read as:
header("Content-Length: ".filesize($file)); // or $filesize in your case.
Missing filesize()

Force download FLV file not working in PHP

am integrating force download using php. when i download the flv files and open in video players its shows error.
$Filename = '/* file name */';
header('Content-Description: File Transfer');
header("Content-type: video/flv");
header("Cache-Control: no-cache");
header("Content-Transfer-Encoding: binary");
header('Content-Disposition: attachment; filename=test.flv' );
header("Pragma: no-cache");
header('Content-length: '.filesize($Filename));
$hFPi = fopen ("$Filename", "rb");
while (!feof($hFPi))
{
$sBuf = fread ($hFPi, filesize($Filename) );
echo $sBuf;
}
fclose ($hFPi);
Please help..
$Filename = '/* file name */';
$path = "../../upload/";
$file = $path.$filename;
savedata1();
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$filename");
header("Content-Type: application/flv");
header("Content-Transfer-Encoding: binary");
readfile($file);
this will help u. Try it in ur code and u will find ur answer...
This code working great to download mp4, flv, mpeg file from my end.
Here:
$file_name = The Downloaded video file name,
$file_path = Base Path of the original file in the server.
header('Pragma: public'); // required
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=$file_name");
header("Content-Type: video/mpeg");
header("Content-Transfer-Encoding: binary");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0', false);
header('Cache-Control: private', false); // required for certain browsers
ob_clean();
flush();
readfile($file_path);
exit;
Try
$Filename = 'test.flv';
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-type: video/flv");
header("Content-Disposition: attachment; filename=".basename($filename).";" );
header("Content-Transfer-Encoding: binary");
readfile("$Filename ");
This is what I do to force a download of a file (for me it's ZIP but it should work for any file type though). Keep in mind you'll have to tweak it as I store my db information differently than you probably do.
header("Content Description: File Transfer");
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must revalidate");
header("Content-Type: application/zip");
header("Content-Disposition: attachment; filename=".basename(".".$filepath)."");
header("Content-Length: " . filesize(".".$filepath));
header("Content-Transfer-Encoding: binary");
ob_clean();
flush();
readfile(".".$filepath);

Categories