Example #1
0
 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;
 }
Example #2
-2
 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;
 }