Jump to content
Sign in to follow this  
abdelelbouhy

zipping folder

Recommended Posts

hi guys i'm having a problem zipping files to folder what is happing the script zip the folder and add some files to that folder then it download the folder but when i unzip the folder i find empty files with 0 KB but when i download via FTP( the unzipped files) contain content any idea the code is like that $zip = new ZipArchive; generate the filegenerateAmazonSkuCSV($arra_sku_uk,$csvsavefilepath,'cb_uk');$csvdowloadfilepath = 'files/csv/amazoninventorysku/';$file_type = 'application/csv';$file_name = "cb_uk_amazon_stock.csv";$file = DIR_FS_ADMIN.$csvdowloadfilepath . $file_name;if ($zip->open(DIR_FS_ADMIN.$csvdowloadfilepath .'changingbag_skus.zip', ZIPARCHIVE::CREATE) != TRUE) {die ("Could not open archive");}$zip->addFile($csvsavefilepath,$file_name);$zip->addFile($csvsavefilepath,$another_file);$zip->close();then download the file $file_found = downloadAmazonSkuFile( $file, $file_name, $file_type ); the function for downloadfunction downloadAmazonSkuFile( $file, $file_name, $file_type ){ if( ! is_file( $file ) ){return false; } $filesize = filesize( $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, post-check=0, pre-check=0');header('Pragma: public');header('Content-Length: ' . filesize($file));ob_clean();flush();readfile($file); return true; }#func many thanks

Share this post


Link to post
Share on other sites

If that variable contains a folder then that is the problem, you're telling it to zip a folder which has no data, which is why the filesize is 0. The first parameter to addFile is the full filename you want to add, check the documentation for that method for more information about how it works.

Share this post


Link to post
Share on other sites

many thanks is there is anyway in php let me download more than a file in one http request the problem is after i create the five files i need to download them all together that why i'm trying to zip them

Share this post


Link to post
Share on other sites

Yeah, zip is the way to do that, you can't send more than one file at once. We do the same thing here, just zip them.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...