当用户使用facebook登录时,我尝试从Facebook上获取他们的照片并将其上传到我自己的网站服务器但是我收到错误未定义的偏移量1,我不知道我为什么会这样做在这里得到这个错误是代码
$url = "https://graph.facebook.com/$fbid/picture?width=410&height=310"; //$fbid is the fbid of user //
$no = imd(); // imd); is a function that generat random string //
$name = basename($url);
list($txt, $ext) = explode(".", $name);
$name = $txt.time();
$jo = ".jpg";
$name = $no.$jo;
$upload = file_put_contents("profile/upload/$name",file_get_contents($url));
$pic = $name;
答案 0 :(得分:0)
正如我在上面的评论中所说,错误来自list($txt, $ext) = explode(".", $name);
,因为爆炸的结果是一个只有一个元素的数组array(1) { [0]=> string(28) "picture?width=410&height=310" }
您可以将代码简化为:
$url = "https://graph.facebook.com/$fbid/picture?width=410&height=310"; //$fbid is the fbid of user //
$no = imd(); // imd); is a function that generat random string //
// $name = basename($url); // COMMENT THIS since you have another assignment for this variable below
// list($txt, $ext) = explode(".", $name); // you didn't use $ext, and since we commented out the next line, $txt won't be used
// $name = $txt.time(); // COMMENT THIS since you have another assignment for this variable below
$jo = ".jpg";
$name = $no.$jo;
$upload = file_put_contents("profile/upload/$name",file_get_contents($url));
$pic = $name;