Jump to content
Joe

zip file image upload problem

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!

Share this post


Link to post
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

Share this post


Link to post
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?

Share this post


Link to post
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

Share this post


Link to post
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.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

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 ..."

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By EyeDentify
      Hello dear PW gurus.

      I have stumbled over a strange error that i all of sudden got when trying to upload an image to a images field on a page.
      There where images allready stored in the field that i wanted to keep, but during the upload the error apear and after that all images are gone from the field and i can´t upload any, i just get the error every time.
      I am running ProcessWire 3.0.153 dev.
      Update:
      After looking in the assets folder i find the folder for the page and the image files seems to be there including the ones i tried to upload when the error occured.
      But they don´t show up in the images field in the page editor.
       
      The error reported:
       
      SQLSTATE[01000]: Warning: 1265 Data truncated for column 'ratio' at row 1 And here is a screenshot of the event:

      The TracyDebugger Error reporting:

      I hope you fine folks could point me in a direction.
      But it seems our old pal set_time_limit() is back.

      Regards, EyeDentify
    • By Matt_P
      Hi everyone,
      I am new to Processwire and am hoping that you will be able to help me out.
      I have currently taken over a website from one of my colleagues and have been asked to implement a gallery.  I have created the appropriate fields and code but have come across an issue when trying to upload images to the field.
      Initially I uploaded multiple images of varying sizes and I found that the loading bar reaches the end very quickly then the loading icon/graphic just continues to spin, I waited for an hour or so for them to load but it never did, it just kept spinning. I then reloaded the page and the images were not shown in the field.
      I decided to then upload one small image (roughly 200KB) and again it did the same as above. I left the site 24 hours to see if it would fix itself. However when that time had passed and I tried again it failed again.
      I asked my colleague if he had any issues with uploading images but apparently it was fine when he was using it.
      Does anyone know what is causing this and if there is a fix?
      See attached image.
      Thanks,
      Matt

    • By Rachid Finge
      I'm building a smartphone app that allows users to record a voice clip and send it to our server, which runs ProcessWire. Files are sent over HTTPS Post, currently without any sort of authentication.
      I've succeeded using the WireUpload class to fetch the uploaded file from the $_FILES super global. Where I get in trouble is when I try to add the audio file to the audio page, where there's an Input field called 'audiofile'. Whenever I try to use any file related method, an Internal Server Error occurs.
      Here's my code, which runs in the page's template.
      <?php Header("Content-Type: text/plain"); $upload_path = $config->paths->assets . "files/audio/"; $u = new WireUpload('files'); $u->setMaxFiles(1); $u->setOverwrite(false); $u->setValidExtensions(array('mp3', 'mp4', 'm4a')); $u->setDestinationPath($upload_path); // I can confirm through my FTP client that the file sent through POST actually shows up in the $upload_path location. $fileresult = $u->execute(); // This is the File input field in my template. Doing print_r($audiofield) confirms this is an existing object. $audiofield = $fields->get("audiofile"); // Trying this for the heck of it, but all that results is HTTP 500. $audiofield->deleteAll(); foreach($fileresult as $filename) { // I've seen various examples on what to do now. Here's one that causes a 500 error. $page->'audiofile' = $upload_path . $filename; // This seems the most logical thing to do, but also causes HTTP 500. $audiofield->add($upload_path . $filename); // Unlinking succeeds (given that I comment out the lines that cause the HTTP 500 errors) unlink($upload_path . $filename); } // We never get to this phase. $page->save(); ?> Things of note:
      Server runs PHP 5.4.4-14+deb7u8 on Debian with Apache/2.2.22.  File uploading through the admin on the audio page works without issues, also when uploading multiple files at once or sequentially. I've confirmed the owner of $upload_path to be www-data and its permissions to be 755. What's the final step I'm missing to add the audio file to the input field on my page?
    • By danielholanda
      Quick question!
      I have everything prepared. I created the web locally with my MAMP. So I have a web working perfectly with CMS processwire, locally. I want to upload this to a hosting server. I suppose I have to install again processwire in this server, or not?. UPloading all these files via FTP to the online server will be enough? Or if I upload via FTP all my files I will still have to create all the fileds again in the online hosting? Or will thee settings be automatic?
      Pleas let me know what I would have to do?
      Thank you very much!
      Dani
×
×
  • Create New...