Jump to content

zip file image upload problem


Joe
 Share

Recommended Posts

Hi,

I have an image field, the "decompress zip files" box is checked and "Max files" is set to "0". I´ve set "zip" as an allowed file extension, since otherwise the upload field did not accept zips.

So I can upload zip files now. But the contained images are not displayed in the "select image" dialog when trying to add them with the editor. I suppose they have not been unpacked. The page´s folder in /site/assets/files/ is still empty.

When I upload zip files to my server using the cPanel file manager or ftp I can unpack them on the server. So I´m not sure, it may still be a server setting that prevents automatic unpacking. I guess I can ask my server support. But maybe someone here knows something?

Thanks!

Link to comment
Share on other sites

But the contained images are not displayed in the "select image" dialog when trying to add them with the editor.

Not sure here but how do you expect the zipped images to be displayed in the select image dialog ?

Some background service or property/config of your editor ?

Anyway, did you check write permissions for your file path /site/assets/files/ ?

To check if your hosting server accepts automatic unzipping run the following script:

first specify a directory to unzip the files to

make sure this directory has write permissions

<?php

     $zip = new ZipArchive;

     $res = $zip->open('my_zip_file.zip');

     if ($res === TRUE) {

         $zip->extractTo('my_extract_to_dir/');

         $zip->close();

         echo 'ok';

     } else {

         echo 'failed';

     }

?>

  • Like 1
Link to comment
Share on other sites

Hello pwired,

Thank you for your handy little script! :) It worked and and shows my server accepts automatic unzipping.

Not sure here but how do you expect the zipped images to be displayed in the select image dialog ?

Some background service or property/config of your editor ?

Well, in the image field Input field settings there is a checkbox "Decompress ZIP files?" The comment there says "If checked, ZIP archives will be decompressed and all valid files added as uploads (if supported by the hosting environment). Max files must be set to 0 (no max) in order for ZIP uploads to be functional."

So my assumption was that the zip file would therefore be unzipped automatically upon uploading it with this field and the images would be available with the page, just as if they were uploaded individually. So am I misunderstanding something here?

Link to comment
Share on other sites

The unzipping in that part of ProcessWire doesn't use ZipArchive, and it needs to be updated. ZipArchive didn't used to be very common, so calling an unzip utility from the shell (what PW does) used to be more reliable across servers. Unfortunately that method doesn't work on Windows servers. Also, ZipArchive is very common now and this part of PW just needs to be updated to use it instead of the older method. 

  • Like 1
Link to comment
Share on other sites

Thank you Ryan! :) No problem, it´s not a big deal for me currently if zip uploads don´t work.

One thing though: mine is an Apache server, not Windows. If I understand you correctly you are saying only on a Windows server it would not work.

Link to comment
Share on other sites

It's possible for it not to work on an Apache server too, if unzip isn't installed (which would be unusual) or if exec() is disabled (more common). There's also a chance unzip just isn't in the executable path on your server. You might see if you can locate where unzip is on the server.. it would usually be /usr/bin/unzip or /usr/local/bin/unzip. If you can login via ssh, you might be able to find it by typing "which unzip". Anyway, once you know where it is, you can take this line from /site/config.php:

/**        
 * uploadUnzipCommand: shell command to unzip archives, used by WireUpload class. 
 *
 * If unzip doesn't work, you may need to precede 'unzip' with a path.
 *  
 */ 
$config->uploadUnzipCommand = 'unzip -j -qq -n /src/ -x __MACOSX .* -d /dst/'; 

and prepend it with the server path: 

$config->uploadUnzipCommand = '/usr/bin/unzip -j -qq -n /src/ -x __MACOSX .* -d /dst/';
  • Like 2
Link to comment
Share on other sites

  • 2 weeks later...

Thank you Ryan!

Yes, exec() was disabled and I changed that. I was able to confirm that /usr/bin/unzip actually is the path on my server. But changing the line in config.php like you mention above didn´t have any effect so far. I upload the zip with the images field and it is shown there, but only as the zip, the zipped images therein are not displayed.

   

But like I said, this is not an important issue for me at the moment, just tried to make it work in case I need it at some point in the future.

I really would like to thank you for your fast responses when a problem is mentioned here in the forums. I´m amazed at how you find the time to sort through all the different issues so quickly! And also the responses from other members I have found most useful. All this together with the great functionality really makes it a pleasure to work with Processwire!

  • Like 1
Link to comment
Share on other sites

The unzipping in that part of ProcessWire doesn't use ZipArchive, and it needs to be updated. ZipArchive didn't used to be very common, so calling an unzip utility from the shell (what PW does) used to be more reliable across servers. Unfortunately that method doesn't work on Windows servers. Also, ZipArchive is very common now and this part of PW just needs to be updated to use it instead of the older method. 

Hello Ryan,

I´m not sure if by the above you meant that it´s been updated already - I just downloaded the latest PW version at GitHub and installed that. But the problem still persists. I have changed the line in config.php to

"$config->uploadUnzipCommand = 'unzip -j -qq -n /src/ -x __MACOSX .* -d /dst/'; "

(and back to the default for a test) and also verified again that exec is activated.

So for the moment I don´t know...   Like I said, this is not an urgent thing for me, just trying to work it out eventually...

Greetings

Link to comment
Share on other sites

  • 2 weeks later...

Joe, we haven't updated to ZipArchive in that part of ProcessWire yet. But if you know exec() is enabled, then try prepending your server path to the uploadUnzipCommand so that rather than "unzip ..." it says "/usr/bin/unzip ..."

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...