使用 php 保存 IMDb 海报

发布于 2024-10-03 04:26:43 字数 891 浏览 0 评论 0原文

我正在为自己制作一个脚本来列出我最喜欢的电影。所以我几乎完成了它,但我无法使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许一世地老天荒 2024-10-10 04:26:46

在我的 Macbook 上运行这个对我来说很有效:

<?php
file_put_contents('./t0120689.jpg', file_get_contents('http://ia.media-imdb.com/images/M/MV5BMTUxMzQyNjA5MF5BMl5BanBnXkFtZTYwOTU2NTY3._V1._SX214_CR0,0,214,314_.jpg'));
?>

如果您将其托管在某个服务器上,则需要将 php ini 设置 allow_url_include 设置为打开,以便您可以获取域外的请求。

Running this worked for me on my Macbook:

<?php
file_put_contents('./t0120689.jpg', file_get_contents('http://ia.media-imdb.com/images/M/MV5BMTUxMzQyNjA5MF5BMl5BanBnXkFtZTYwOTU2NTY3._V1._SX214_CR0,0,214,314_.jpg'));
?>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文