0

I'm running 2 simple function:

<?php
    $zipUrl = "path_of_original.zip"
    $zipFilename = "local_path_and_name_of.zip"
    $unzipPath = "destination_of_unzipped_files"

    upload_archive ($zipUrl, $zipFilename);
    unzip_archive ($zipFilename, $unzipPath);
?>
  • the 1st, upload a .zip archive on server

    function upload_archive ($zipUrl, $zipFilename){
        define('BUFSIZ', 4095);
        $rfile = fopen($zipUrl, 'r');
        $lfile = fopen($zipFilename, 'w');
    
        while(!feof($rfile))
            fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
    
        fclose($rfile);
        fclose($lfile);}
    
  • the 2nd, unzip the archive

    function unzip_archive ($zipFilename, $unzipPath){
        $zip = new ZipArchive;
        $res = $zip->open($zipFilename);
    
        if ($res === TRUE) {
            $zip->extractTo($unzipPath);
            $zip->close();
            echo 'success!';
        } else {
            echo 'error!';
        }
    }
    

when these 2 functions are executed separately everything's fine, but when executed in sequence I can't appreciate the output of the second function (unzip).

I think the problem is that the .zip file is still locked in write by the first function.

any Suggestions?

Angelo.

Angelo
  • 1
  • 2
  • What do you mean with `functions`? a real function, wrapped by `function() {}` ? If it is, please update your question with corrected code and funtions call. Otherwise: in your code `$fileZip` is not defined: it is defined somewhere? – fusion3k Mar 11 '16 at 15:01
  • Hi, I've updated the code, I think is more clear now. Thank you! – Angelo Mar 11 '16 at 17:29
  • The code works totally fine for me (in sequence). If the functions works separated, the problem is outside the functions, so verify correct pathnames (echoes variables values) in your code, verify file permission and **activate error reporting** to isolate the problem. – fusion3k Mar 11 '16 at 17:59

0 Answers0