2013-12-14 130 views
1

我想使用file_put_contents從URL(Facebook和Twitter)下載和創建多種類型(不同大小)的圖像。使用file_put_contents下載圖像

我的劇本是這樣的:

$image = $user->getAvatarSocial(); 
//image like: => https://abs.twimg.com/sticky/default_profile_images/default_profile_4.png 
file_put_contents($image, file_get_contents('php://input')); 

但我收到此錯誤:

Warning: fopen(http://abs.twimg.com/sticky/default_profile_images/default_profile_4.png): failed to open stream: HTTP wrapper does not support writeable connections

我使用的Symfony 2.3.7。

+0

[未能打開流:HTTP包裝不支持可寫連接]的可能重複(http://stackoverflow.com/questions/9748076/failed-to-open-stream-http-wrapper-does-not-support可寫連接) – Thibault

+0

@Thibault圖像不在我的服務器 – Twinsen

回答

1

您無法嘗試將內容放入遠處的圖像文件中。

file_put_contents需要兩個參數:

  • 第一個是本地路徑
  • 二是內容

在這裏你給寫文件的HTTP路徑。您的PHP腳本無法寫入Twitter Web服務器。

要做到這一點,你將不得不使用Twitter API或其他東西。

什麼在你的php://input

+0

http://php.net/manual/en/wrappers.php.php – Twinsen

+0

'$ image = $ user-> getAvatarSocial(); file_put_contents('foo.jpg',file_get_contents($ image));' – Twinsen