dryift6733
2013-02-08 15:45
浏览 320
已采纳

PHP中的imagecreatefromjpeg()函数出错

When using the below php code it shows an error

<?php
$path="/hari002244/album/f41b6b54811c.jpg";
$src = imagecreatefromjpeg($path);
?>

It shows

SCREAM: Error suppression ignored for
Warning: imagecreatefromjpeg(/hari002244/album/f41b6b54811c.jpg): failed to open stream: No such file or directory in C:\wamp\www
ewEmptyPHP.php on line 3

But when using

<?php
$path="f41b6b54811c.jpg";
$src = imagecreatefromjpeg($path);
?>

It doesn't show any error.

I had typed the path in URL bar and checked whether file exists.It is working perfectly.

Can you tell me why this error occurs? and also how to overcome this?

Thanks in advance.

图片转代码服务由CSDN问答提供 功能建议

使用下面的php代码时显示错误 \ n

 &lt;?php 
 $ path =“/ hari002244 / album / f41b6b54811c.jpg”; 
 $ src = imagecreatefromjpeg($ path); 
?&gt; 
  <  / pre> 
 
 

显示

  SCREAM:
警告忽略错误抑制:imagecreatefromjpeg(/hari002244/album/f41b6b54811c.jpg):无法打开 stream:第3行的C:\ wamp \ www 
ewEmptyPHP.php中没有这样的文件或目录
   
 
 

但使用时

 &lt;?php 
 $ path =“f41b6b54811c.jpg”; 
 $ src = imagecreatefromjpeg($ path); 
?&gt; 
  <  / pre> 
 
 

它没有显示任何错误。

我在URL栏中输入了路径并检查文件是否存在。它运行正常。

你能告诉我为什么会出现这个错误吗? 以及如何克服这个问题?

提前致谢。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douyinjiao9351 2013-02-08 15:47
    已采纳

    The first path, "/hari002244/album/f41b6b54811c.jpg" is an absolute path, it starts from the root of the whole file system. Chances are, this path does not exist.

    In the second case, it is just a filename "f41b6b54811c.jpg" which is relative to / located in the current working directory, which of course exists.

    点赞 评论
  • dongmo8943 2013-02-08 15:51

    Got the answer

    Instead of "/hari002244/album/f41b6b54811c.jpg"

    Should be used "http://localhost/hari002244/album/f41b6b54811c.jpg"

    点赞 评论

相关推荐 更多相似问题