Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 接收未定义的偏移量1_Php_Facebook - Fatal编程技术网

Php 接收未定义的偏移量1

Php 接收未定义的偏移量1,php,facebook,Php,Facebook,当用户使用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 st

当用户使用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;

正如我在上面的评论中所说,错误来自
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;

您的$url出现错误。我认为您发送了错误的参数。错误来自
list($txt,$ext)=explode(“.”,$name)
因为explode的结果是一个只有一个元素的数组
数组(1){[0]=>字符串(28)“picture?width=410&height=310”}
@Monty这个参数完全正确,就像有人访问facebook时重定向到@PrinceG如何纠正这个错误?@PrinceG那么如何获得图像的名称,我很困惑