facebookarchive / php-graph-sdk

The Facebook SDK for PHP provides a native interface to the Graph API and Facebook Login. https://developers.facebook.com/docs/php
Other
3.17k stars 1.95k forks source link

Failed to create FacebookFile entity in foreach loop #1172

Closed fd6130 closed 4 years ago

fd6130 commented 4 years ago

I'm using Symfony 4.4 and i found this issue when tried upload each photo through foreach loop:

$request->files is $_FILES in PHP

/**
* @var images[] $request->files->get('images')
*/
foreach($request->files->get('images') as $image) {

       $response = $fb->post('/{page-id}/photos', [
            'source' => $fb->fileToUpload($image),
            'published' => 'false'
          ]);
    $graphNode = $response->getGraphNode();
    // ....
}

It give me error like Failed to create FacebookFile entity. Unable to read resource: /tmp/phpInUGiA.

But when i try upload single photo (select one photo and upload it), it have no problem:

$response = $fb->post('/{page-id}/photos', [
            'source' => $fb->fileToUpload($request->files->get('images')),
            'published' => 'false'
          ]);
$graphNode = $response->getGraphNode();
// ....

This one success.

Do we have any solution to deal with this issue?

fd6130 commented 4 years ago

I found a solution for this.

I use VichUploader upload all the images, and then use UploaderHelper to get the path of the image.

And it seems works now.