[英]PHP ZipArchive, disable outputs/echos/logs
I am running PHP ZipArchive in an API and it outputs like adding: uploads/AUFIC/ps.csv (stored 0%)
in the body of the response when it runs, how can I disable this output from getting printed? 我在API中运行PHP ZipArchive,其输出类似于在运行时在响应正文中
adding: uploads/AUFIC/ps.csv (stored 0%)
,如何禁止输出此输出?
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: 这是包含ZipArchive的函数,它在周围排列一些文件,然后将这些文件压缩并上传到S3,然后返回该zip文件的URL:
private function downloadPackage($schoolPrefix,$schoolZipPassword,$csvFilePath) {
$ret = array('status' => false, "message" => "", "response" => array());
try {
$s3 = Aws\S3\S3Client::factory(array('region' => getenv('omitted_AWS_REGION_2')));
$s3->registerStreamWrapper();
$bucket = 'autoregistration.omitted.com';
// production needs to be read from env var
$prefix = 'production/PackageFiles/';
$objects = $s3->getIterator('ListObjects', array(
'Bucket' => $bucket,
'Prefix' => $prefix
));
$zip = new ZipArchive;
$zipfilename = $schoolPrefix.'_omitted'.date('YmdHis').'.zip';
$zipfilepath = 'uploads/'.$zipfilename;
$zip->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->addFromString($objectname, $contents);
}
}
// pass the school prefix in params
$school_objects = $s3->getIterator('ListObjects', array(
'Bucket' => $bucket,
'Prefix' => '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->addFromString(basename($school_object['Key']), $contents);
$foundcsv = true;
}
}
if(!$foundcsv) throw new Exception ('Can not find the csv file.', 400);
$zip->close();
$output = system("zip -P '".$schoolZipPassword."' ". $zipfilepath . " ".$csvFilePath);
$key = 'production/'.$schoolPrefix.'/'.$zipfilename;
$s3result = $s3->putObject(array('Bucket'=>$bucket,'Key' => $key, 'SourceFile' => $zipfilepath));
//$ret['s3_url'] = $s3result['ObjectURL'];
$ret['s3_url'] = $s3->getObjectUrl($bucket, $key, '+2 days');
$ret['status'] = true;
unlink($zipfilepath);
} catch (Exception $e) {
$ret['status'] = false;
$ret['message'] = $e->getMessage();
}
return $ret;
}
I would start by changing this: 我将从更改此内容开始:
return $ret;
To this: 对此:
return;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.