PHP:从 Flickr 下载图像到本地服务器(通过 CURL?)
我有一个 Wordpress 网站,我使用 Flickr feed 来获取最新的图像。通过使用脚本,每次在 Flickr 上有新图像时,我都会创建一个新帖子,但是图像缩略图源来自 Flickr,当我按缩略图时,我会重定向到 Flickr 图像。
我想关闭我的 WordPress 网站以获取任何新内容,并希望将其与所有第三方 API 和服务关闭,因此我想浏览我的 Flickr 帖子列表并下载我提到的每个缩略图和图像。
我的博客上包含图像的 Flickr 帖子示例如下所示:
<a href="http://www.flickr.com/photos/2332432@N06/554435234/">
<img alt="My ALT text" src="http://farm8.staticflickr.com/2213/35554564_5fhe10fj22_m.jpg"
</a>
如果可以的话,我想同时下载缩略图和大图,但否则可接受的解决方案是仅下载缩略图(图像来自farm8.staticflickr.com)。
我尝试过不同的方法,但没有一个有效。我尝试过的一个是这样的(我用它来提取 Vimeo 缩略图,因此我想我会在 Flickr 缩略图上工作):
$ch = curl_init($the-image-url-variable);
$fp = fopen('$thename.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
当我使用这段代码时,它确实在我的文件夹中生成了一张图像,但该图像无效,无法显示任何内容。
任何帮助或建议将不胜感激。
真诚
- 梅斯蒂卡
I’ve a Wordpress site where I uses my Flickr feed to get my latest images. By using a script, I create a new post everytime I’ve a new image on Flickr but, the image thumbnail source is from Flickr and when I press the thumbnail I’m redirected to the Flickr image.
I want to close down my wordpress site for any new content and want to close it off from all third part APIs and Services, so I want to run through my list of Flickr posts and download every thumbnails and images I’m referring to.
An example of a Flickr post on my blog with an image looks like this:
<a href="http://www.flickr.com/photos/2332432@N06/554435234/">
<img alt="My ALT text" src="http://farm8.staticflickr.com/2213/35554564_5fhe10fj22_m.jpg"
</a>
If it can be done I would like to download both the thumbnail and the large picture but otherwise an acceptable solution would be just to download the thumbnail image (the image from farm8.staticflickr.com).
I’ve tried different approached but none have worked. One I tried was this (which I’m using to extract the Vimeo thumbnail, so therefor I thought I would work on the Flickr Thumbnail):
$ch = curl_init($the-image-url-variable);
$fp = fopen('$thename.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
When I’m using this code, it does indeed generate an image in my folder but the image is invalid and can’t show any content..
Any help or suggestions would be appreciated.
Sincere
- Mestika
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论