PHP getimagesize 函数失败

发布于 2024-12-20 16:47:14 字数 932 浏览 1 评论 0原文

我正在本地使用 WordPress,由于某种原因,当我从 page.php 调用 getimagesize() 来检索大小时,它不起作用。我收到警告:

getimagesize(http://localhost:8080/wordpress/wp-content/themes/minimize/_/images/img-2.jpg ) 
[function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.0 404 
Not Found in C:\wamp\www\wordpress\wp-content\themes\minimize\page.php on line 13

调用它的实际代码是:

$items = get_post_meta($post->ID, 'test');

        foreach($items as $item) {

            $img_pth = 'http://localhost:8080/wordpress/wp-content/themes/HTML5-Reset-Wordpress-Theme/_/images/'.$item;

            list($width, $height) = getimagesize($img_pth);

            echo '<img src="'.$img_pth.'" height="'.$height.'" width="'.$width.'">';

        }

我是使用 PHP 的新手,所以如果我的代码中存在非常明显的内容,我不会感到惊讶,但我认为我想做的是非常简单直接。我尝试将 localhost 更改为 127.0.0.1,正如我在另一个线程中看到的那样,但无济于事。图像正在渲染,因此图像路径是正确的,但功能失败。感谢您能给我任何帮助...

I'm working with wordpress locally and for some reason when I call getimagesize() from page.php to retrieve the sizes it does not work. I get the warning:

getimagesize(http://localhost:8080/wordpress/wp-content/themes/minimize/_/images/img-2.jpg ) 
[function.getimagesize]: failed to open stream: HTTP request failed! HTTP/1.0 404 
Not Found in C:\wamp\www\wordpress\wp-content\themes\minimize\page.php on line 13

The actual code that is calling it is:

$items = get_post_meta($post->ID, 'test');

        foreach($items as $item) {

            $img_pth = 'http://localhost:8080/wordpress/wp-content/themes/HTML5-Reset-Wordpress-Theme/_/images/'.$item;

            list($width, $height) = getimagesize($img_pth);

            echo '<img src="'.$img_pth.'" height="'.$height.'" width="'.$width.'">';

        }

I'm new to working with PHP so I wouldn't be surprised if it is something very obvious with my code, but I think what I'm trying to do is pretty easy and straight forward. I've tried changing localhost to 127.0.0.1 as I saw in another thread but to no avail. The images are being rendered, so the image paths are correct, but the function is failing. Thanks for any help I can get...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

触ぅ动初心 2024-12-27 16:47:14

我也遇到了同样的问题。
请改用文件的相对路径。

I had the same problem.
Use relative path to the file instead.

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