PHP getimagesize 函数失败
我正在本地使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到了同样的问题。
请改用文件的相对路径。
I had the same problem.
Use relative path to the file instead.