php - Create a temporary folder to keep the files in structure and make it downloadable by compressing the folder -


in project, have files related items on server shown below:

item-1  => file1.txt, file2.pdf , file3.doc item-2  => file4.pdf, file5.ppt item-3  => file6.txt, file7.docx , file8.ppt .... 

i can above items $this->getallitems() , loop through each item.

i trying compress these files in structured way. so, user can understand files belong items.

what trying keep files related respected items in folder , wrap them in "main" folder (this should happen in temporary path) compress , let user download compress folder. so, files in structured way shown below:

main    item-1       --> file1.txt       --> file2.pdf       --> file3.doc    item-2       --> file4.pdf       --> file5.ppt    item-3         --> file6.txt       --> file7.docx       --> file8.ppt 

while searching here, got link compress files (but not folders) in temporary path , make compressed folder available download.

ps: the compressing should happen every download request users.

i not sure whether correct or not.. worked.

i modified loop part of code available on link.

# loop through each file foreach($files $file){      # download file     $download_file = file_get_contents($file);      # create empty folder     $zip->addemptydir($itemname);      #add above created new folder in zip     $zip->addfromstring($itemname . '/' . basename($file), $download_file);  } 

in above code, $itemname item name fetched dynamically while looping in $this->getallitems() had mentioned in post.

please let me know if correct or not.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -