| | |
Error reading zip
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
I have this function whereby it allows people to download zip file but then i try to open it after downloading it, there was this error msg that says "Error reading zip".
If you really want help you should post your code, or at least the portion you feel is causing the problem. Offhand it sounds like the zip file on the server has gotten corrupted somehow.
[PHP] $zipfile = new zipfile();
$zipfile -> add_dir("files/");
$dir = '../files';
$filename = "testing.mp3";
$pathname = "$dir/$filename";
$fr = fopen($pathname, 'r');
$data = fread($fr, filesize($pathname));
fclose($fr);
$zipfile->add_file($filedata, "files/".$filename);
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=testing.zip");
echo $zipfile->file();
[/PHP]
This is the part i feel is causing the problem. i have a zipfile class which creates zip files
$zipfile -> add_dir("files/");
$dir = '../files';
$filename = "testing.mp3";
$pathname = "$dir/$filename";
$fr = fopen($pathname, 'r');
$data = fread($fr, filesize($pathname));
fclose($fr);
$zipfile->add_file($filedata, "files/".$filename);
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=testing.zip");
echo $zipfile->file();
[/PHP]
This is the part i feel is causing the problem. i have a zipfile class which creates zip files
Have you tried:
[PHP]header("Content-type: application/x-zip");[/PHP]
Also, you open the file and put the data into $data. Then you use the class and use the variable $filedata. Should they be the same??
[PHP]header("Content-type: application/x-zip");[/PHP]
Also, you open the file and put the data into $data. Then you use the class and use the variable $filedata. Should they be the same??
•
•
•
•
Originally Posted by DanceInstructor
Have you tried:
[PHP]header("Content-type: application/x-zip");[/PHP]
Also, you open the file and put the data into $data. Then you use the class and use the variable $filedata. Should they be the same??
i try already but cannot still error reading zip but the file was in the downloaded because i see the file size of the zip is the same as the file size of the file.
•
•
Join Date: Jan 2005
Posts: 18
Reputation:
Solved Threads: 2
Hi
You should be using a content length header so the browser does not add \r?\n to the stream buffer...
Also your application-x-type is wrong...
demo
You should be using a content length header so the browser does not add \r?\n to the stream buffer...
Also your application-x-type is wrong...
PHP Syntax (Toggle Plain Text)
if ( strstr ( strtolower ( $_SERVER['HTTP_USER_AGENT'] ), 'msie 5.5' ) ) { $att = ''; } else { $att = ' attachment;'; } header ( 'Cache-control: max-age=31536000' ); header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); header ( 'Content-Length: ' . filesize ( $filename ) ); header ( 'Content-Type: application/x-zip-compressed; name="' . basename ( $filename ) . '"' ); header ( 'Content-Disposition:' . $att . ' filename="' . basename ( $filename ) . '"' ); header ( 'Content-Transfer-Encoding: binary' ); readfile ( $filename );
demo
•
•
•
•
Originally Posted by demo
Hi
You should be using a content length header so the browser does not add \r?\n to the stream buffer...
Also your application-x-type is wrong...
PHP Syntax (Toggle Plain Text)
if ( strstr ( strtolower ( $_SERVER['HTTP_USER_AGENT'] ), 'msie 5.5' ) ) { $att = ''; } else { $att = ' attachment;'; } header ( 'Cache-control: max-age=31536000' ); header ( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' ); header ( 'Content-Length: ' . filesize ( $filename ) ); header ( 'Content-Type: application/x-zip-compressed; name="' . basename ( $filename ) . '"' ); header ( 'Content-Disposition:' . $att . ' filename="' . basename ( $filename ) . '"' ); header ( 'Content-Transfer-Encoding: binary' ); readfile ( $filename );
demo
i did not use zip file anymore then can work already. i am able to download the file successfully. the next problem arises up.
In the first place, the mp3 file has a ID3 tag. after it has been downloaded, the ID3 tag is deleted. I figure it must be the codinng though because when i download it straight from server through ftp. Everything is alright. i myself really do not know what is wrong.
This is the part of code which i think might be the problem
In the first place, the mp3 file has a ID3 tag. after it has been downloaded, the ID3 tag is deleted. I figure it must be the codinng though because when i download it straight from server through ftp. Everything is alright. i myself really do not know what is wrong.
This is the part of code which i think might be the problem
•
•
•
•
$currentdir = '../mp3_files';
$trackname = $trackdb->retrieveTrackName($track_oid);
$filename = "$trackname.mp3";
$pathname = "$currentdir/$filename";
$fr = fopen($pathname, 'r');
$filedata = fread($fr, filesize($pathname));
//fclose($fr);
//$zipfile->add_file($filedata,$filename);
header ( 'Content-Length: ' . filesize ( $pathname ) );
header("Content-type: application/octet-stream");
header("Content-disposition: attachment; filename=$filename");
header ( 'Content-Transfer-Encoding: binary' );
readfile($pathname);
![]() |
Other Threads in the PHP Forum
- Previous Thread: Very new to PHP
- Next Thread: Help with phpBB for novice
| Thread Tools | Search this Thread |
301 apache api array autosuggest beginner binary broken cakephp checkbox class cms code compression cron curl data database date display dropdownlist dynamic echo email eregi error execution file files folder form forms function functions google href htaccess html httppost if...loop image include insert ip javascript joomla jquery key library limit link links login mail md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf pdfdownload php phpvotingscript problem query radio random recursion remote screen script search searchbox server session sessions sms sorting source space sql syntax system table tutorial update upload url validator variable video volume votedown web website youtube zend





