PHP ~ write content to file

今天用facebook connect..........

他的大頭照是回傳

https://graph.facebook.com/'.$uid.'/picture

這網址會輸出一個jpg檔

所以不是這網址就是一個jpg

我之前的寫法是直接copy

遇到這情況就不行複製了....

要改用php讀取這網址的內容~~~~~~再把它寫入成一個jpg檔就好了

-------------------------------------------------------------------------------------------
$photoUrl = 'https://graph.facebook.com/'.$uid.'/picture';

$contents = file_get_contents($photoUrl);
$handle = fopen('img/users/1234.jpg', 'w+');

if($handle){
if(!fwrite($handle, $contents)){
die("couldn't write to file.");
}
echo "success writing to file";
}
-------------------------------------------------------------------------------------------

reference
http://www.php-learn-it.com/php_files/php_file_write.html

沒有留言: