0

I have a webpage that logs on to facebook and displays a list of all friends with their picture. I want to download all those pictures in order to a zip folder on my server for download. Each picture has a unique id, but needs to be downloaded in order and renamed with the naming scheme 1.jpg, 2.jpg, etc.

I have tried a few things but nothing has worked. First I tried:

$i = 1;
foreach ($friends["data"] as $value) {
$url = 'https://graph.facebook.com/' . $value["id"] . '/picture?type=large';
copy($url,"$i.jpg");
$i++;
}

I thought this worked, but when I tried to open the images, they were all 0kb-also this does not save all the contents as a zip for easy download.

I then tried this:

$i=1;
foreach ($friends["data"] as $value) {
$fileName = '<img src="https://graph.facebook.com/' . $value["id"] . '/picture?type=large"/> <br />';
echo $fileName;

header("Content-Disposition: attachment; filename='".$fileName."'");
$target=$fileName;
$newName=$i.'jpg';
rename($target, $newName);
$i++;
}

But this gave an error:

Warning: Cannot modify header information - headers already sent by (output started at /home/xxx/public_html/xxx.com/facebooksdk/facebook-php-sdk/examples/test.php:70) in /home/xxx0/public_html/xxx.com/facebooksdk/facebook-php-sdk/examples/test.php on line 138

Warning: rename(graph.facebook.com/xx/picture?type=large"/> <br />,1jpg) [function.rename]: No such file or directory in /home/xxx/public_html/xxx.com/facebooksdk/facebook-php-sdk/examples/test.php on line 141

This second code I may not have even written correctly though...any help would be greatly appreciated!

4

1 回答 1

0

这似乎有效:

    $i = 1;
    foreach ($friends["data"] as $value) {

        echo '<img src="https://graph.facebook.com/' . $value["id"] . '/picture?type=large"/> <br />'; 
        $url = 'https://graph.facebook.com/' . $value["id"] . '/picture?type=large';
        $img = 'photos/'.$i.'.jpg';
        file_put_contents($img, file_get_contents($url));
        $i++;
  }

虽然我还没有解决如何压缩文件夹。

于 2013-09-03T17:50:07.407 回答