tags:

views:

17

answers:

1

I'm using CURL to grab contents of a zip file on a remote server and then save it to a temp_zip_file.zip and then use PclZip class to extract the contents of a file.

The problem is that on some servers, the server will not allow my script to create a temporary zip file out of the CURL return so I can use it for pclzip extraction.

What i would like to do is skip the creation of a temporary zip file and just use the string return of the original CURL with pclzip class for extraction.

I have to use pclzip because some servers do no allow the default php zip class to be used.

Below is the curl function used to grab content from the remote file.

function copy_file($download_file)
{
    //get file
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$download_file);
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_FAILONERROR, true);
    curl_setopt($ch, CURLOPT_AUTOREFERER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    $file = curl_exec($ch);
    curl_close($ch);
    $fp = fopen('temp_zip_file.zip', 'w');
    fwrite($fp, $file);
    fclose($fp);
   //exit;
}

Below is a copy of my pcl unzip function, in which $download_file is 'temp_zip_file.zip':

function zip_extract($download_file, $store_path, $remove_path)
{
 //echo 1; exit;
 //echo $remove_path; exit;
 $archive = new PclZip($download_file);
 $list = $archive->extract(PCLZIP_OPT_REMOVE_PATH, $remove_path, PCLZIP_OPT_PATH, $store_path, PCLZIP_OPT_REPLACE_NEWER );
 if ($list == 0) 
 {
  //echo "death here"; exit;
  die("Error : ".$archive->errorInfo(true));

 }
 else
 {
  //print_r($list); exit;
  return 1;

 }

}

Thank you for any support

A: 

If you want to use gzopen() on something else then a file, the Data wrapper might be what you're looking for. Keep in mind it is read-only, no writing possible. That being said, I've yet to come across a system which doesn't allow me to write in the TMP dir (the TMP environmental variable in Linux, the TMPDIR environmental variable in Windows I believe....)

Wrikken