Koozali.org: home of the SME Server

Zipper des fichiers en php

Offline Dominique

  • 2
  • +0/-0
Zipper des fichiers en php
« on: December 19, 2012, 04:09:44 PM »
Sous wamp j'ai utilisé la classe ZipArchive en modifiant le php.ini (decommenter le php_zip). Une fois la page php créé chargé sur le sme server la classe n'est pas trouvée. Comment valider la classe sous le server sme pour pouvoir zipper des fichiers ou existe t'il d'autre classe zip utilisable ?
Merci de votre aide.

Offline mmccarn

  • *
  • 2,656
  • +10/-0
Re: Zipper des fichiers en php
« Reply #1 on: December 20, 2012, 01:45:02 PM »
I found a script online and modified it to test ZipArchive on my SME servers.

On SME 8, the script works without any server changes.

On SME 7.6, the script will not run.

To test:
1) Create <ibay>
2) cd /home/e-smith/files/ibays/<ibay>/html
3) create folder "ziptest"
4) put some files in "ziptest"
5) create /home/e-smith/files/ibays/<ibay>/html/ztest.php (content shown below)
6) browse to http://<mysmeserver>/<ibay>/ztest.php
7) Test the results using "unzip -l /home/e-smith/files/ibays/<ibay>/html/my-archive.zip"

Contents of "ztest.php":
Code: [Select]
<?php

// Adding files to a .zip file, no zip file exists it creates a new ZIP file

// increase script timeout value
ini_set('max_execution_time'5000);

// create object
$zip = new ZipArchive();

// open archive 
if ($zip->open('my-archive.zip'ZIPARCHIVE::CREATE) !== TRUE) {
    die (
"Could not open archive");
}

// initialize an iterator
// pass it the directory to be processed
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator("ziptest/"));

// iterate over the directory
// add each file found to the archive
foreach ($iterator as $key=>$value) {
    
$zip->addFile(realpath($key), $key) or die ("ERROR: Could not add file: $key");
}

// close and save archive
$zip->close();
echo 
"Archive created successfully.";
?>


Avec de la chance ça vous donnera ce qu'il vous faut...

Offline Dominique

  • 2
  • +0/-0
Re: Zipper des fichiers en php
« Reply #2 on: December 21, 2012, 12:06:08 PM »
Thanks mmccarn for your answer.
Unfortunately, the SME server is not at the last version.
Following your answer it's the reason why it doesn't work.
I found a trick to use instead the linux Zip embeded on the sme server.
On php file I use the command "shell_exec('zip ...." with options which are available with the man list.
It works well for my use.
I wish you a Merry Christmas.
Regards