Example #1
0
 public static function createFromLocalFile($file_name, $mime_type = null)
 {
     //Try to guess.  Might be questionable on non-*nix machines
     if ($mime_type === null) {
         $finfo = new \finfo(FILEINFO_MIME_TYPE);
         $info = $finfo->file($file_name);
         if ($info !== false) {
             $mime_type = $info;
         }
     }
     $content_length = filesize($file_name);
     $path_info = pathinfo($file_name);
     $instance = new self();
     $instance->fromStringArray(array('MimeType' => $mime_type, 'ContentLength' => $content_length, 'FileName' => $path_info['basename']));
     $instance->setLocalHandle(fopen($file_name, 'r'));
     return $instance;
 }
Example #2
0
 public static function createFromBinary($data, $file_name, $mime_type)
 {
     $content_length = strlen($data);
     $instance = new self();
     $instance->fromStringArray(array('MimeType' => $mime_type, 'ContentLength' => $content_length, 'FileName' => $file_name));
     $instance->content = $data;
     return $instance;
 }