Expand zip files
Permalink
Hello,
I want to adda feature for my users.
They can send a zip (via fileManager)
In the zip, they push multiples pictures ( as an album)
After this i want to create a bloc for display theses pictures.
For the block config, the user must select the zip file.
wat is the best way for manage the zip expension ?
First idea :
the first time visitor view the block, the controller expand the zip in a cache folder, and the content must be available for others requests.
Second idea :
The file manager expand the file ( in a background task ) and maintain a link between the file and the expanded version. ( better for manage files deleting or updating )
Do you have somes idea, for create this ?
Thanks
I want to adda feature for my users.
They can send a zip (via fileManager)
In the zip, they push multiples pictures ( as an album)
After this i want to create a bloc for display theses pictures.
For the block config, the user must select the zip file.
wat is the best way for manage the zip expension ?
First idea :
the first time visitor view the block, the controller expand the zip in a cache folder, and the content must be available for others requests.
Second idea :
The file manager expand the file ( in a background task ) and maintain a link between the file and the expanded version. ( better for manage files deleting or updating )
Do you have somes idea, for create this ?
Thanks
Hello,
I have take the "pictures file" as exemple for simplification.
In real, the zip contain somes datas files generated by a homemade app.
If fact, the zip contain lot of small files witn folders hierarchy.
The zip "packager" is the best way for simplify transfert.
My question is about the best way for manage zip file.
Can it's possible to trigger a controller just after the "load file" event ( i don't know if this event exist) ?
I think it's possible to expand zip to a folder ( where ?) and link this to the file ( with an attribute key ?)
In fact i want to crete an addOn that modify the core of concrete5
I have take the "pictures file" as exemple for simplification.
In real, the zip contain somes datas files generated by a homemade app.
If fact, the zip contain lot of small files witn folders hierarchy.
The zip "packager" is the best way for simplify transfert.
My question is about the best way for manage zip file.
Can it's possible to trigger a controller just after the "load file" event ( i don't know if this event exist) ?
I think it's possible to expand zip to a folder ( where ?) and link this to the file ( with an attribute key ?)
In fact i want to crete an addOn that modify the core of concrete5
Okay, that makes sense. PHP has the ability to deal with zip archives in the standard library so that shouldn't be a problem:
http://php.net/manual/en/ref.zip.php...
Best solution of course depends on your exact use case. Here are three ideas:
Easiest, most straightforward: Your second idea is the better one. Assuming you don't need the files in the zip to be under FileManager control, just the .zip itself, you could unzip them into a directory in the site root, and add an attribute to the zip file containing the path to the uncompressed archive. Otherwise you'll end up repeatedly decompressing the archive, which is probably not what you want. Obviously you'll need to have a fair amount of custom code to handle importing the .zip, how to "view" the file, and cleaning up when the file is deleted or a new version is added.
Most elegant: You can actually read individual files directly out of a zip archive (see the reference above), so you don't even need to decompress it... just keep the original zip in the FileManager and write a custom handler to pick out individual files from the archive. This potentially has two nice side-effects: you get the same permissions model from the original zip, and if you're really clever you may not even have to decompress the files before you send them, assuming that they are compressed with something equivalent to gzip, and you can set the HTTP headers appropriately (just guessing on this last one, but it should be possible). This probably won't perform well if you are trying to display many files on the same page. You'll have to write custom code to view the file and send the file (which I think already exists in Concrete5 as the "forceDownload" method, or something like that).
Cutting edge/high-risk/insanely awesome: have the browser pull the entire file with an Ajax request, decompress it in JavaScript (there are libraries for that), and handle all of the display on the client side.
http://php.net/manual/en/ref.zip.php...
Best solution of course depends on your exact use case. Here are three ideas:
Easiest, most straightforward: Your second idea is the better one. Assuming you don't need the files in the zip to be under FileManager control, just the .zip itself, you could unzip them into a directory in the site root, and add an attribute to the zip file containing the path to the uncompressed archive. Otherwise you'll end up repeatedly decompressing the archive, which is probably not what you want. Obviously you'll need to have a fair amount of custom code to handle importing the .zip, how to "view" the file, and cleaning up when the file is deleted or a new version is added.
Most elegant: You can actually read individual files directly out of a zip archive (see the reference above), so you don't even need to decompress it... just keep the original zip in the FileManager and write a custom handler to pick out individual files from the archive. This potentially has two nice side-effects: you get the same permissions model from the original zip, and if you're really clever you may not even have to decompress the files before you send them, assuming that they are compressed with something equivalent to gzip, and you can set the HTTP headers appropriately (just guessing on this last one, but it should be possible). This probably won't perform well if you are trying to display many files on the same page. You'll have to write custom code to view the file and send the file (which I think already exists in Concrete5 as the "forceDownload" method, or something like that).
Cutting edge/high-risk/insanely awesome: have the browser pull the entire file with an Ajax request, decompress it in JavaScript (there are libraries for that), and handle all of the display on the client side.
Thanks,
I get infos about your ideas.
The zip management via javascript is not good for my project ( and really dangerous) because all datas in zip ares not used ( depend to the request via the front end script )
The first solution ( expand in a folder and get a link in the files attribute ) is the best choise a this time.
Now i must get more infos about the fileManager.
I must add custom methods for zip management ( expand, content validation, and suppress methods for cleanning expanded files )
Thanks.
I get infos about your ideas.
The zip management via javascript is not good for my project ( and really dangerous) because all datas in zip ares not used ( depend to the request via the front end script )
The first solution ( expand in a folder and get a link in the files attribute ) is the best choise a this time.
Now i must get more infos about the fileManager.
I must add custom methods for zip management ( expand, content validation, and suppress methods for cleanning expanded files )
Thanks.
Oh, look, Concrete5 has this:
http://www.concrete5.org/documentation/developers/system/archives...
Another thought, be sure to test that the zip files created by the client can actually be decompressed by the server before you commit to a lot of coding. Not all libraries are created equally.
http://www.concrete5.org/documentation/developers/system/archives...
Another thought, be sure to test that the zip files created by the client can actually be decompressed by the server before you commit to a lot of coding. Not all libraries are created equally.
Serious question: why go through the trouble of having your users zip up their photos (most people have no idea what that means), when you can just use Concrete5's built in multiple file uploader?
If I were trying to solve this problem (and as a matter of fact I am doing so right now, except for PDFs instead of images), I would use the multi-file uploader and just make sure that appropriate metadata was assigned during the import process. For your case wouldn't it be as simple as just adding the files to a FileSet?
Keep in mind that for a sufficiently large archive, you could actually time-out the connection while attempting to deflate.