fromResource() public static method

Returns the size in bytes from the given resource.
public static fromResource ( resource $handle ) : string
$handle resource
return string
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function write($key, $content)
 {
     $this->ensureBucketExists();
     $options = $this->getOptions($key, array('Body' => $content));
     /*
      * If the ContentType was not already set in the metadata, then we autodetect
      * it to prevent everything being served up as binary/octet-stream.
      */
     if (!isset($options['ContentType']) && $this->detectContentType) {
         $fileInfo = new \finfo(FILEINFO_MIME_TYPE);
         if (is_resource($content)) {
             $contentType = $fileInfo->file(stream_get_meta_data($content)['uri']);
         } else {
             $contentType = $fileInfo->buffer($content);
         }
         $options['ContentType'] = $contentType;
     }
     try {
         $this->service->putObject($options);
         if (is_resource($content)) {
             return Util\Size::fromResource($content);
         } else {
             return Util\Size::fromContent($content);
         }
     } catch (\Exception $e) {
         return false;
     }
 }