php – Facebook SDK 上傳照片

用 FB SDK 上傳的時候,欄位 source 須要指定表單 form 傳送的 input:file,不過要記得在開頭加上 @ 小老鼠就對了,不知道為什麼呢….

			foreach ($_FILES['upl']['name'] as $key => $val)

				$DataList[]								=	$this->facebook->api("/$v/me/photos", "POST", array
					'message'							=>	$_POST['message'],
					'source'							=>	"@" . $_FILES['upl']['tmp_name'][$key], //記得開頭加 @
					'privacy'							=>	array 
															value    =>	$_POST['privacy']





Set file upload support in the SDK. Your server must be configured to support file uploads in order to use this feature.

You can also set this parameter via the fileUpload property in the $config array when you instantiate the Facebook object.


// Upload a photo to a user’s profile
// Your app needs publish_actions permission for this to work

$img = '/tmp/mypic.png';

$photo = $facebook->api(
    'source' => '@' . $img,
    'message' => 'Photo uploaded via the PHP SDK!'