PHP ZipArchive,禁用 outputs/echos/logs
PHP ZipArchive, disable outputs/echos/logs
我是 运行 PHP ZipArchive 在 API 中,它在运行时在响应正文中输出类似 adding: uploads/AUFIC/ps.csv (stored 0%)
的内容,如何禁用此输出从打印?
这是包含 ZipArchive 的函数,它会整理一些文件,然后压缩这些文件并将其上传到 S3,然后 return 该 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;
}
我将从改变这个开始:
return $ret;
为此:
return;
我是 运行 PHP ZipArchive 在 API 中,它在运行时在响应正文中输出类似 adding: uploads/AUFIC/ps.csv (stored 0%)
的内容,如何禁用此输出从打印?
这是包含 ZipArchive 的函数,它会整理一些文件,然后压缩这些文件并将其上传到 S3,然后 return 该 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;
}
我将从改变这个开始:
return $ret;
为此:
return;