title: PHP ZipArchive, disable outputs/echos/logs
body: <p>I am running PHP ZipArchive in an API and it outputs like <code>adding: uploads/AUFIC/ps.csv (stored 0%)</code> in the body of the response when it runs, how can I disable this output from getting printed?</p>
  
  <p>Here's the function that contains ZipArchive, it arranges some files around then zips those files and upload it to S3 then return the URL of that zip file:</p>
  
  <pre><code>    private function downloadPackage($schoolPrefix,$schoolZipPassword,$csvFilePath) {
      $ret = array('status' =&gt; false, "message" =&gt; "", "response" =&gt; array());
      try {
          $s3 = Aws\S3\S3Client::factory(array('region' =&gt; getenv('omitted_AWS_REGION_2')));
          $s3-&gt;registerStreamWrapper();
          $bucket = 'autoregistration.omitted.com';
          // production needs to be read from env var
          $prefix = 'production/PackageFiles/';
          $objects = $s3-&gt;getIterator('ListObjects', array(
              'Bucket' =&gt; $bucket,
              'Prefix' =&gt; $prefix
          ));
          $zip = new ZipArchive;
          $zipfilename = $schoolPrefix.'_omitted'.date('YmdHis').'.zip';
          $zipfilepath = 'uploads/'.$zipfilename;
          $zip-&gt;open($zipfilepath, ZipArchive::CREATE);
          foreach ($objects as $object) {
              if(basename($object['Key']) != 'PackageFiles')
              {
                  $contents = file_get_contents("s3://{$bucket}/{$object['Key']}");
                  $objectname = (basename($object['Key']) == 'SchoolPrefix.ps1') ? $schoolPrefix.'.ps1' : basename($object['Key']);
                  $zip-&gt;addFromString($objectname, $contents);
              }
          }
          // pass the school prefix in params
          $school_objects = $s3-&gt;getIterator('ListObjects', array(
              'Bucket' =&gt; $bucket,
              'Prefix' =&gt; 'production/'.$schoolPrefix
          ));
          foreach ($school_objects as $school_object) {
              if(basename($school_object['Key']) == 'ps.csv')
              {
                  $contents = file_get_contents("s3://{$bucket}/{$school_object['Key']}");
                  $zip-&gt;addFromString(basename($school_object['Key']), $contents);
                  $foundcsv = true;
              }
          }
          if(!$foundcsv) throw new Exception ('Can not find the csv file.', 400);
  
          $zip-&gt;close();
          $output = system("zip -P '".$schoolZipPassword."' ". $zipfilepath . " ".$csvFilePath);
          $key = 'production/'.$schoolPrefix.'/'.$zipfilename;
          $s3result = $s3-&gt;putObject(array('Bucket'=&gt;$bucket,'Key' =&gt; $key, 'SourceFile' =&gt; $zipfilepath));
          //$ret['s3_url'] = $s3result['ObjectURL'];
          $ret['s3_url'] = $s3-&gt;getObjectUrl($bucket, $key, '+2 days');
          $ret['status'] = true;
          unlink($zipfilepath);
      } catch (Exception $e) {
          $ret['status'] = false;
          $ret['message'] = $e-&gt;getMessage();
      }
      return $ret;
  }
  </code></pre>