2013-12-14 131 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