本文整理匯總了PHP中storage::begin方法的典型用法代碼示例。如果您正苦於以下問題:PHP storage::begin方法的具體用法?PHP storage::begin怎麽用?PHP storage::begin使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類storage
的用法示例。
在下文中一共展示了storage::begin方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: gzip_compress
/**
* GZIPs the temp file
*
* From http://stackoverflow.com/questions/6073397/how-do-you-create-a-gz-file-using-php
* Based on function by Kioob at:
* http://www.php.net/manual/en/function.gzwrite.php#34955
*
* @param string $source Path to file that should be compressed
* @param integer $level GZIP compression level (default: 6)
* @return boolean true if operation succeeds, false on error
*/
public function gzip_compress($level = 6)
{
if ($this->tempfile === NULL) {
return;
}
$source = $this->tempfile;
$file = new storage($source);
$dest = $file->begin();
$mode = 'wb' . $level;
$error = false;
$chunk_size = 1024 * 512;
if ($fp_out = gzopen($dest, $mode)) {
if ($fp_in = fopen($source, 'rb')) {
while (!feof($fp_in)) {
gzwrite($fp_out, fread($fp_in, $chunk_size));
}
fclose($fp_in);
} else {
$error = true;
}
gzclose($fp_out);
} else {
$error = true;
}
if ($error) {
return false;
} else {
$file->commit();
return true;
}
}