benkyma -1 Light Poster

Hi, I want a script that will upload an image to a user's Facebook account.
So far I have this code, but it's not working correctly. I seem to get an ID returned, but no image is uploaded to the profile:

function do_post_request($url, $data) 
{ 
		$file= $data;
		$args = array(
		   'message' => 'Photo from application'
		);
		$args[basename($file)] = '@' . realpath($file);
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL, $url);
		curl_setopt($ch, CURLOPT_HEADER, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_setopt($ch, CURLOPT_POST, true);
		curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
		$pageData = curl_exec($ch);
		//returns the photo id
		print_r($pageData);
}

if (!empty($_FILES)) {

	$tempFile = $_FILES['Filedata']['tmp_name'];
	$access_token = $_GET['token'];
	$image_up_url = "https://graph.facebook.com/me/photos?access_token=" .$access_token;
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
	$targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];	
	$fileTypes  = str_replace('*.','',$_REQUEST['fileext']);
	move_uploaded_file($tempFile,$targetFile);
	do_post_request($image_up_url,$targetFile);
		

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.