rick Posted June 22, 2018 Share Posted June 22, 2018 I know I have to be missing something simple. I need to specify via API a url to a zip file which contains images and have them saved in a back-end images field when the admin form is submitted. I have built a process module which generates a dynamic form and processes the form once submitted. Everything functions correctly except adding a zip archive of images to a multi-image field. The images field works fine if the zip file is selected on a local machine. The addimageurls module does not work with zip files. The wirehttp->download will save the zip file to the specified folder, but the path returned is not accepted by the images field. // $zip can be filespec or uri $page->of(false); $page->images->add($zip); $page->save(); The images field has no file limit, zip extension added, and decompress zip is enabled. Can someone provide the correct procedure please? Link to comment Share on other sites More sharing options...
Zeka Posted June 23, 2018 Share Posted June 23, 2018 I think you have to unzip it firstly and then add images to your images field $zip = $config->paths->cache . "archive.zip"; $dst = $config->paths->cache . "temp-zip/"; $items = $files->unzip($zip, $dst); $page->of(false); if(count($items)) { foreach($items as $item) { $page->images->add($item); } } $page->save(); 1 Link to comment Share on other sites More sharing options...
rick Posted June 23, 2018 Author Share Posted June 23, 2018 Thank you @Zeka. Your solution does work. The base images field allows for a local zip file to be added via the Choose File option. I haven't found a means to accomplish this from the API. For example, from the API: Download the desired file.zip file to a local folder. $this->config->paths->assets . "some-folder/" . basename( $url ); Pass the file from that local folder path to the images field. $page->images->Add( "/var/www/test/site/assets/some-folder/file.zip" ); Save the page. Does not work. However, if I select Choose File and navigate to that same folder, select file.zip, and click Open, the zip file contents are added to the images field. So there is a difference I haven't yet been able to determine. Link to comment Share on other sites More sharing options...
LostKobrakai Posted June 24, 2018 Share Posted June 24, 2018 15 hours ago, rick said: So there is a difference I haven't yet been able to determine. The unzipping behaviour is part of the inputfield itself not the PageFiles/PageImages class: https://github.com/processwire/processwire/blob/341342dc5b1c58012ae7cb26cffe2c57cd915552/wire/modules/Inputfield/InputfieldFile/InputfieldFile.module#L943-L945 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now