本文整理汇总了PHP中Uploader::upload_large_part方法的典型用法代码示例。如果您正苦于以下问题:PHP Uploader::upload_large_part方法的具体用法?PHP Uploader::upload_large_part怎么用?PHP Uploader::upload_large_part使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Uploader
的用法示例。
在下文中一共展示了Uploader::upload_large_part方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload_large
public static function upload_large($file, $options = array())
{
$src = fopen($file, 'r');
$temp_file_name = tempnam(sys_get_temp_dir(), 'cldupload.' . pathinfo($file, PATHINFO_EXTENSION));
$upload = $upload_id = NULL;
$chunk_size = \Cloudinary::option_get($options, "chunk_size", 20000000);
$public_id = \Cloudinary::option_get($options, "public_id");
$index = 0;
$file_size = filesize($file);
while (!feof($src)) {
$current_loc = $index * $chunk_size;
if ($current_loc >= $file_size) {
break;
}
$dest = fopen($temp_file_name, 'w');
stream_copy_to_stream($src, $dest, $chunk_size);
fclose($dest);
if (phpversion() >= "5.3.0") {
clearstatcache(TRUE, $temp_file_name);
} else {
clearstatcache();
}
$temp_file_size = filesize($temp_file_name);
$range = "bytes " . $current_loc . "-" . ($current_loc + $temp_file_size - 1) . "/" . $file_size;
try {
$upload = Uploader::upload_large_part($temp_file_name, array_merge($options, array("public_id" => $public_id, "content_range" => $range)));
} catch (\Exception $e) {
unlink($temp_file_name);
fclose($src);
throw $e;
}
$upload_id = \Cloudinary::option_get($upload, "upload_id");
$public_id = \Cloudinary::option_get($upload, "public_id");
$index += 1;
}
unlink($temp_file_name);
fclose($src);
return $upload;
}
示例2: upload_large
public static function upload_large($file, $options = array())
{
$src = fopen($file, 'r');
$temp_file_name = tempnam(sys_get_temp_dir(), 'cldupload.' + pathinfo($file, PATHINFO_EXTENSION));
$upload = $upload_id = NULL;
$public_id = \Cloudinary::option_get($upload, "public_id");
$index = 1;
while (!feof($src)) {
$dest = fopen($temp_file_name, 'w');
stream_copy_to_stream($src, $dest, 20000000);
fclose($dest);
try {
$upload = Uploader::upload_large_part($temp_file_name, array_merge($options, array("public_id" => $public_id, "upload_id" => $upload_id, "part_number" => $index, "final" => feof($src))));
} catch (\Exception $e) {
unlink($temp_file_name);
fclose($src);
throw $e;
}
$upload_id = \Cloudinary::option_get($upload, "upload_id");
$public_id = \Cloudinary::option_get($upload, "public_id");
$index += 1;
}
unlink($temp_file_name);
fclose($src);
return $upload;
}