Jump to content

unzip command shell


nellone
 Share

Recommended Posts

Hi everyone, im running PW in a local windows machine with xampp, i've noticed that PW uses some linux shell commands as "unzip" that obviously windows cannot recognize.

Is there some way to take a different approach while i need to unzip an archivie? For example using a php code for unzipping files instead of shell commands.

thank you!

Link to comment
Share on other sites

the problem comes when i upload a zip file (the language pack) through the "language support" module.

I can see the file is uploaded correctly, but nothing more happens, so i checked in the apache error log and i saw the problem, 'unzip' is not recognized as an internal or external command

This is the option in config file:

/**
 * 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/';

but i have no idea how it can be fixed.

I know the basic php script to unzip files:

<?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';
     }
?> 

but i have not the knowledge to implement this in PW

Link to comment
Share on other sites

Hi, when you are on your own local machine and want to 'upload' a file and wants to get it unzipped, you should provide the path to an unzip-app and all needed params / flags for it. (A commandline app!) If you don't have one, you may go and fetch 7z. It comes with an additional commandline prog called '7za.exe'
 
Put it somewhere into your systempath, open a shell command (cmd.exe) and type in 7za -h or 7za --help to get a list of available commands and switches. If you have figured out the needed command and switch/es, write this into your PW-site config.php, instead of the unix there.

I use 7za.exe sometimes with PHP-CLI on my local machine, - but only to zip archives. I never have used it to unzip via cli.

  • Like 3
Link to comment
Share on other sites

i really appreciate your advice horst, but i'm working on a local machine only to setup a website before it will be published online.

I don't know if the host will support linux shell commands... and i'm pretty shure i will not have permissions to run executables...

i'm wondering why PW don't use php to unzip files... i'm pretty familiar with wordpress enviroment and i never had problems like this :\

Link to comment
Share on other sites

Hi, ok,- you want to install a language pack what is a zip-archive.
I'm new to PW and don't get touched with language-packs til now, but have read before a minute the Instructions:

Instructions

To install a language pack, you must have the ProcessWire Language Support module installed. This is included with ProcessWire, so all you have to do is click to Modules > Language > Language Support > install.

Once you have Language Support installed, you can install this language pack by going to Setup > Languages > Add New Language. Enter a title and name for the language and save.


Next, you can install the files for the language pack. If your system supports ZIP uploads, you can simply drag the ZIP file for the language pack into the files field.

If your system doesn't support ZIP uploads,


then you'll want to unzip the language pack and drag the JSON files (as a group, or individually) into the files field.

Save.

So, I cannot see really a problem with it!  ;)

Link to comment
Share on other sites

i already installed and uninstalled language pack, because the language pack translates an half of the words....

the problem of unzipping files is where this approach is replicated to anyone else uploading script.

Anyway, thank you very much for the help... ^_^

Link to comment
Share on other sites

i'm wondering why PW don't use php to unzip files...

That's actually an interesting question. I for one wasn't even aware of PHP ZipArchive's existence and don't really know how well (or badly) it behaves, but it might make sense to use it if it's a) widely supported, b) cross-platform and c) fully functional -- either as a primary solution combined with "if class_exists('ZipArchive')" or a fallback to current method.

Link to comment
Share on other sites

That's actually an interesting question. I for one wasn't even aware of PHP ZipArchive's existence and don't really know how well (or badly) it behaves, but it might make sense to use it if it's a) widely supported, b) cross-platform and c) fully functional -- either as a primary solution combined with "if class_exists('ZipArchive')" or a fallback to current method.

 

I have only used a phpclass that rely on the php-zip-extension. This work on Linux and Windows.

With this it is very simple and robust usage:

	$unzip = new unzip2($ZIPFILE);
	$unzip->debug = 1;  // 0 = off
	$list = $unzip->getList();

	foreach($list as $fileName=>$zippedFile)
	{
		if( ! in_array($zippedFile['type'], array('jpg','png','gif') )
		{
			continue;
		}

		$res = $unzip->unzip($fileName, $dest_path);
	}

Pete uses the php-zip-function with his Module ScheduleBackups. I have tested it on windows and the created archives provided much information of compressed files, more than some other solutions.

Link to comment
Share on other sites

I think that that class is in most PHP versions from the last few years so I'll give my views on zip in PHP here since it's relevant to the discussion.

There will always be some hosts that don't compile PHP with all of the modules but you have to draw the line somewhere to stop having to include 3rd party libraries in your modules and I think that PHP's zip functionality is pretty standard so I'd say go with that.

My only reservation is that it doesn't have recursion built in (I mean you would think there would be an option to zip a directory and all children as standard but noooo ;)) and you'll be gathering a lot of info from people's comments and Stafkoverflow rather than the actual docs but you'll get there if you persevere with it.

Link to comment
Share on other sites

ZipArchive does seem to be pretty widely adopted now. It wasn't when that existing ZIP code was originally written. I've been meaning to change it over to ZipArchive, but just haven't gotten around to it. It's on my to-do list. 

  • Like 3
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...