Reputation: 55
I am working with facebook graph api, in my code i want to store a user profile image url in my database & the image store in my database file, it can find the source file also show it but it can't store image my database. The error says that:
file_put_contents(celebrity_u_look_alike/youtube_star/fb_user_image/img_1264053943663652.png): failed to open stream: No such file or directory in /home/smartcarsassocia/public_html/celebrity_u_look_alike/youtube_star/youtube_star.php on line 101
My source code shown below :
try {
$requestPicture = $fb->get('/me/picture?redirect=false&height=250&width=250'); //getting user picture
$requestProfile = $fb->get('/me'); // getting basic info
$picture = $requestPicture->getGraphUser();
$profile = $requestProfile->getGraphUser();
$url= $picture['url'];
echo $url;
$filename = 'img_' . $profile_data['id'] . '.png';
echo $filename;
$path1 = "celebrity_u_look_alike/youtube_star/fb_user_image/" . basename($filename);
$image_file = file_get_contents($url);
file_put_contents($path1, $image_file );
//file_put_contents($path2, file_get_contents($url));
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
Upvotes: 1
Views: 10180
Reputation: 26258
This is because:
file_put_contents($path1, $image_file );
the path you have provided in $path1
doesn't exist physically. So make sure the directory exist. If not, then create it using mkdir()
function.
Upvotes: 1