Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have used a code for creating zip file form user checked checkbox files. I get the following error message:
PK!Ýü•7f [Content_Types].xml ¢( ´TËnÂ0¼Wê?D¾V‰¡‡ªªú8¶H¥ì
XõKöòúûnDUA*å)YïÌììăÑÚšl 1iïJÖ/z,'½ÒnV²ÉK~ϲ„Â)a¼ƒ’m
±Ñðúj0ÙHu»T²9bxà<É9X‘ ÀQ¥òÑ ¤×8ãAÈO1~ÛëÝqé‚Ãk6$N{9›êÍ+P9Y
¢†vuÇGD²ìÃï»ÆoR€”wàͳ¶
ÌIÊŠ~‰‰˜8›ïWòZè“"V0}¿˜ûßÀ»„´ù“>þÁŒýuQwHoî·áÿÿPK!‘·óN_rels/.rels ¢(
Œ’ÛJA†ïßaÈ}7Û "ÒÙÞH¡w"ë„™ìw̤ھ½£ ºPÛ^æôçËOÖ›ƒ›Ô;§<¯aYÕ
Ø›Gßkxm·‹PYÈ[š‚g GΰinoÖ/<‘”¡<Œ1«¢â³†A$>"f3°£\…ȾTºI S‘ÌõŒ«º¾ÇôWš™¦ÚY
igï#µÇX6_Ö]7~ fïØˉÈaoÙ.b*lIÆrj)õ,l0Ï%‘b¬
6ài¢ÕõDÿ_‹Ž…, ¡ ‰Ïó|uœZ^tÙ¢yǯ;!Y,}{ûCƒ³/h>ÿÿPK!Öd³Qú1word/rels/document.xml.rels
¢( ¬’ÍjÃ0„ï…¾ƒØ{-;ý¡„ȹ”#®ûŠ½þ¡²$´›¶~û
CR‡÷â‹Fhæ“´›íwoÄ'êœU%)´¥«:Û(x/vwÏ ˆµ´qH°Íoo6¯h4ÇCÔvžDL±¤
eök)©l±×”86îÔ.ôš£ôºüÐ ÊUš>É0Í€ü"Sì+a_݃(›ÿÏvuÝ•øâÊc–¯TÈ/<¼!s¼ÅXd3‰´
¯ƒ¬–¡?'g![?óü4ê¹úÇ%ë9Žþ¶RŽk6Çð°$Cí,ú&gë!/=ÿÿÿPK!æ“KxîQword/document.xmlœTÛnÛ0}°0ôžØɲ´5âë²îi#Ñv
Ȳ-L‰Ž—}ý(²lE‹/’É#žC‘”7·?NÒ¶‹yÆi”ÊÖûþ|?»fI#nK®ÁÊ‚e`·Û÷ï6]^‚h´˜…
ùÐÑåiD# spÒX7Éôuj¸ÿѺ™ã8ª½Ò
é2ËÖl¤‚µÞæ#ÅÌ(á!#…1$‡ªRBŽÛá/Ñ"wcʽbꥦÀ†F¹0±™ÿe£+6ÉáKŒžÎuîµÒóŽúaôv¾t„¼»<1.²·´ÇFŠSÄ%)ü9eb¸²'š8ÿôÿÔ¼95/´ÓHõç"T‹-ÍÒÊcÜ]Òå4‹åcÁ²ìn±Î¾Ü°Éµ“o5FäwŸûHÃpû,R5×zA&4s4Ö¶¤
½” Gäq*ÑnÒx>®J«{¡;²¿®›Æ
øéÐYV£ë‰ðè]/¯îoV}®®~úEhGm¹\ÑSëò†¾?^ÓwÏéêo$ùãûÿ©«×îÇ!)OÚ^ýrÍC$ñy#“°íÝö/yH*œ˜ñ„´½)‘Þµ÷ß»Š×UDb‚}"×qÛ‹”J×—–¤ÃX^æ)InÌEŒ¼Šp)øèÆli¹V[]Š1M<”àÈÞ©OÐP“ô6râ=¯‰’zÀgb
Ig…ÁuSÙ
Here is my code:
header("Content-Description: File Transfer");
header("Content-type: application/zip");
header("Content-Type: application/force-download");// some browsers need this header("Content-Disposition: attachment;
filename=$archive_file_name");
header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header("Content-Length:". " $zipped_size");
ob_clean(); flush();
readfile("$archive_file_name");
unlink("$archive_file_name");
That isn't an error message, that's a zip file rendered as text.
Presumably, after you have generated the zip file, you are sending it to the browser with the wrong Content-Type. Possibly you are setting no Content-Type at all, so PHP will default to text/html.
The browser then gets something it is told is HTML and so it tries to render it as a webpage.
Set the correct content-type in your program:
header("Content-Type: application/zip");
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 days ago.
Improve this question
I am working on a WordPress Website, in which the admin can download the CV of users in PDF or Word Format
When I try to download CV, it randomly gives Network error.
ob_start();
header('Content-Description: File Transfer');
header('Content-Type: ' . $file_mimetype);
header("Content-type: application/force-download");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header('Content-Transfer-Encoding: Binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . #filesize($file_path));
ob_end_clean();
flush();
#readfile($file_path);
exit;
This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 7 years ago.
I read a whole bunch of articles in SO and the internet and tried all of them but I am still unable to create a CSV download functionality in PHP.
Following is my code:
$csvData = #$_POST['csv_data'];
if(trim($csvData))
{
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=data.csv");
header("Expires: 0");
header("Pragma: public");
echo $csvData;
exit;
}
Instead of showing the file save dialog, this keeps printing the CSV data into my browser :( What am I doing wrong here? Any help is much appreciated..
Additional Edit: I am posting this data into my script, which immediately takes this data and tries to download. My script is an include inside another file, will that be a problem? I enabled error_reporting and found that I am getting header already modified error...
In HTTP, headers are sent before any text output.
For that reason, PHP will close your response header if you output any text.
Make sure that you hold any text output before your header modification, for example using the OB-cache.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have physical files which I want users to download on my website. The files are located at:
C:/xampp/htdocs/myfile/uploads/*
I need a PHP script which can download files dynamically on click. Let's say I have the following button which when clicked it triggers magic.php script.
Download file
What PHP code do I need in magic.php to download the file name I passed in the query parameters?
Download link
Download
magic.php page
<?php
$file = 'C:/xampp/htdocs/myfile/uploads/'.urldecode($_GET['file']);
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;
}
?>
Maybe you could do something like this: (Correct me if i am wrong)
<a href="uploads/<?php echo $row['name']; ?>" download="download">
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have used file system to store the files, all files are either word or pdf files. how should i create their downloadable links on client side.
Any help would be appreciated.
you can download file using:
<?php
$file = 'filename.extension';
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));
ob_clean();
flush();
readfile($file);
exit;
}
?>
You can simply write the file path in the href attribute of the <a /> tag...
Download Here
<?php
if (isset($_GET['file'])) {
$file = $_GET['file'];
if (file_exists($file) && is_readable($file) && preg_match('/\.pdf$/',$file)) {
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
}
} else {
header("HTTP/1.0 404 Not Found");
echo "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>";
}
Try the above snippet and name it as download.php!
Once the above has been done, save the file and if needed upload to the server hosting your web page.
Finally, once uploaded, all future .PDF links that you want to be downloaded instead of opened in the browser will need to point to download.php?file=example.pdf, where example.pdf is the name of the PDF you want for the user to download. Below is an example of what a full link could look like.enter code here
Click here to download PDF
Download
This should do the job.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
i am confused in how to allows download the file.zip after the payment.If i redirect them to a download page where is file is placed in sever they can download the file again easily or they can pass that link to anyone.
Any suggestions please!
Don't use a direct link to the file - use a PHP file that serves the file up as a download, but only if a certain session var is found (created in the confirmation of the payment process)
Just like #SmokeyPHP mentioned, just output the file through PHP instead of linking to it directly.
<?php
$file = 'monkey.gif';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
http://php.net/manual/en/function.readfile.php
This way you have a full control over who downloads what. Of course depending on the file size, you may wish to split the file into smaller chunks. You don't want to be buffering 40 MB files in your server memory every 5s. With bigger files, you can use something like this:
<?php
$file = fopen("file.dat", "r");
while (!feof($file)) {
echo fgets($file);
}
fclose($file);
?>
put .zip file outside the webserver;
protect the .zip URL with some rule [e.g. being logged in and having purchased the resource];
associate the .zip URL with an action that reads the actual binary file and forwards it to user [plenty of examples in here].