使用 php 保存 IMDb 海报
我正在为自己制作一个脚本来列出我最喜欢的电影。所以我几乎完成了它,但我无法使用 php 从 IMDb 保存小海报。我使用了 file_put_contents()
函数,但它创建了一个 0kb jpeg 文件。这是我使用的代码:
file_put_contents('./posters/t0120689.jpg', file_get_contents('http://ia.media-imdb.com/images/M/MV5BMTUxMzQyNjA5MF5BMl5BanBnXkFtZTYwOTU2NTY3._V1._SX214_CR0,0,214,314_.jpg'));
当然它不起作用。然后我用了cURL:,
$ch = curl_init(
file_put_contents('./posters/t0120689.jpg', file_get_contents('http://ia.media-imdb.com/images/M/MV5BMTUxMzQyNjA5MF5BMl5BanBnXkFtZTYwOTU2NTY3._V1._SX214_CR0,0,214,314_.jpg');
$fp = fopen('./posters/t0120689.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
也没用。这是 IMDb 中的示例电影页面: http://www.imdb.com/title/tt0120689/< /a>
I'm making a script for myself to list my favorite movies. So I nearly finished it but I cannot save the small poster from IMDb with php. I used the file_put_contents()
function, but it's creating a 0kb jpeg file. here is the code that I used:
file_put_contents('./posters/t0120689.jpg', file_get_contents('http://ia.media-imdb.com/images/M/MV5BMTUxMzQyNjA5MF5BMl5BanBnXkFtZTYwOTU2NTY3._V1._SX214_CR0,0,214,314_.jpg'));
Of course it didn't work. Then I used cURL:
$ch = curl_init(
file_put_contents('./posters/t0120689.jpg', file_get_contents('http://ia.media-imdb.com/images/M/MV5BMTUxMzQyNjA5MF5BMl5BanBnXkFtZTYwOTU2NTY3._V1._SX214_CR0,0,214,314_.jpg');
$fp = fopen('./posters/t0120689.jpg', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
and it didn't work either. This is the example movie page from IMDb: http://www.imdb.com/title/tt0120689/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我的 Macbook 上运行这个对我来说很有效:
如果您将其托管在某个服务器上,则需要将 php ini 设置
allow_url_include
设置为打开,以便您可以获取域外的请求。Running this worked for me on my Macbook:
If you are hosting this on a server somewhere, the php ini setting
allow_url_include
needs to be set to on in order for you te get requests outside of your domain.