2016-10-20 13 views
1

私はUploadcareマルチアップロードウィジェットを使用しており、投稿時にグループIDを取得しています。グループ内のファイルを一覧表示するAPIを呼び出すと、各ファイル(uuid、mime_type、original_filenameなど)に関する特定の情報を抽出したいと考えています。ここでPHPによる配列によるアップロードの繰り返し

は私のコードです:

$privateFiles = $_REQUEST['privateFiles'];  
$ucApi = new Uploadcare\Api(public_key_removed, private_key_removed); 
$group = $ucApi->getGroup($privateFiles); 
$files = $group->getFiles();   

foreach ($files as $ucFile) 
    { 
     echo $ucFile['uuid']; 
    } 

私はこれをしようとすると、私はこのエラーが表示されます。 Fatal error: Cannot use object of type Uploadcare\File as array

私は間違いなく戻ってAPIからデータを取得しますが、単に問題を抱えていますそれを解析しようとしています。ここで私は戻って取得しています何のサンプルです:

Array ([0] => Uploadcare\File Object ([re_uuid_with_effects:Uploadcare\File:private] => !/?(?P[a-z0-9]{8}-(?:[a-z0-9]{4}-){3}[a-z0-9]{12})(?:/(?:-/(?P(?:[^/]+/)+)))?(?[^/]*)! [uuid:Uploadcare\File:private] => 47ff1aa0-eebe-43d0-8803-0578455e82a1 [operations:Uploadcare\File:private] => Array () [api:Uploadcare\File:private] => Uploadcare\Api Object ([public_key:Uploadcare\Api:private] => public_key_removed [secret_key:Uploadcare\Api:private] => private_key_removed [api_host:Uploadcare\Api:private] => api.uploadcare.com [current_method:Uploadcare\Api:private] => GET [cdn_host] => ucarecdn.com [cdn_protocol] => https [retry_throttled:Uploadcare\Api:private] => 1 [userAgentName:Uploadcare\Api:private] => PHP Uploadcare Module [widget] => Uploadcare\Widget Object ([api:Uploadcare\Widget:private] => Uploadcare\Api Object *RECURSION*) [uploader] => Uploadcare\Uploader Object ([host:Uploadcare\Uploader:private] => upload.uploadcare.com [api:Uploadcare\Uploader:private] => Uploadcare\Api Object *RECURSION*) [version] => 1.5.5/5.6 [api_version] => 0.4 [defaultFilters:Uploadcare\Api:private] => Array ([file] => Array ([stored] => [removed] =>))) [operation_list:Uploadcare\File:private] => Array ([0] => crop [1] => resize [2] => scale_crop [3] => effect [4] => preview) [cached_data:Uploadcare\File:private] => Array ([uuid] => 47ff1aa0-eebe-43d0-8803-0578455e82a1 [original_file_url] => https://ucarecdn.com/47ff1aa0-eebe-43d0-8803-0578455e82a1/processes.txt [image_info] => [mime_type] => text/plain [is_ready] => 1 [url] => https://api.uploadcare.com/files/47ff1aa0-eebe-43d0-8803-0578455e82a1/ [original_filename] => processes.txt [datetime_uploaded] => 2016-10-20T19:28:44.314526Z [size] => 8543 [is_image] => [datetime_stored] => [datetime_removed] => [source] => [default_effects] =>) [default_effects] => [filename] =>) [1] => Uploadcare\File Object ([re_uuid_with_effects:Uploadcare\File:private] => !/?(?P[a-z0-9]{8}-(?:[a-z0-9]{4}-){3}[a-z0-9]{12})(?:/(?:-/(?P(?:[^/]+/)+)))?(?[^/]*)! [uuid:Uploadcare\File:private] => 76e4fbca-0133-4863-838f-43b3e47a892e [operations:Uploadcare\File:private] => Array () [api:Uploadcare\File:private] => Uploadcare\Api Object ([public_key:Uploadcare\Api:private] => public_key_removed [secret_key:Uploadcare\Api:private] => private_key_removed [api_host:Uploadcare\Api:private] => api.uploadcare.com [current_method:Uploadcare\Api:private] => GET [cdn_host] => ucarecdn.com [cdn_protocol] => https [retry_throttled:Uploadcare\Api:private] => 1 [userAgentName:Uploadcare\Api:private] => PHP Uploadcare Module [widget] => Uploadcare\Widget Object ([api:Uploadcare\Widget:private] => Uploadcare\Api Object *RECURSION*) [uploader] => Uploadcare\Uploader Object ([host:Uploadcare\Uploader:private] => upload.uploadcare.com [api:Uploadcare\Uploader:private] => Uploadcare\Api Object *RECURSION*) [version] => 1.5.5/5.6 [api_version] => 0.4 [defaultFilters:Uploadcare\Api:private] => Array ([file] => Array ([stored] => [removed] =>))) [operation_list:Uploadcare\File:private] => Array ([0] => crop [1] => resize [2] => scale_crop [3] => effect [4] => preview) [cached_data:Uploadcare\File:private] => Array ([uuid] => 76e4fbca-0133-4863-838f-43b3e47a892e [original_file_url] => https://ucarecdn.com/76e4fbca-0133-4863-838f-43b3e47a892e/XPlaneInstallerLog.txt [image_info] => [mime_type] => text/plain [is_ready] => 1 [url] => https://api.uploadcare.com/files/76e4fbca-0133-4863-838f-43b3e47a892e/ [original_filename] => X-Plane Installer Log.txt [datetime_uploaded] => 2016-10-20T19:28:44.332926Z [size] => 5526 [is_image] => [datetime_stored] => [datetime_removed] => [source] => [default_effects] =>) [default_effects] => [filename] =>))

答えて

0

Uploadcare\Fileはオブジェクトであるので、あなたは1のように扱う必要があります。

UUIDを取得するには、方法があります:$file->getUuid()です。他のメタデータについては

することができますusedata配列:

foreach ($files as $file) 
{ 
    echo $file->getUuid(); 
    echo $file->data['is_image']; 
    echo $file->data['datetime_uploaded']; 
    // etc 
} 
+0

は完璧な作品 - ありがとうございます! – Jason

関連する問題