2016-01-28 2 views
0

Когда пользователь Войти с помощью facebook, тогда я пытаюсь получить их фотографию из facebook и загрузить ее на свой собственный сервер веб-сайта, но я получаю ошибку undefined offset 1, я не знаю, почему я получаю это ошибка здесь кодПолучение неопределенного смещения 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

ваш $ url получает ошибку. Я думаю, что вы отправляете неправильный параметр. – Monty

+1

ошибка из 'list ($ txt, $ ext) = explode (". ", $ Name);' потому что результат explode является массивом с только одним элементом на нем 'array (1) {[0] => string (28) "picture? width = 410 & height = 310"} ' – PrinceG

+0

@Monty параметр абсолютно правильный, как когда кто-то посещает https://graph.facebook.com/$fbid/picture?width=410&height=310 facebook перенаправляет на https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfa1/v/t1.0-1/c25.0.459.320/p320x320/10354686_10150004552801856_220367501106153455_n.jpg –

ответ

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; 
Смежные вопросы