2014-12-15 12:59
浏览 31


I have a problem when checking if a file exists in zend framework 2:

When checking:


which is the absolute route in my computer, it returns true.

When checking:


which is the route from the module, it returns false.

If I make:

echo "<img src='".$this->basePath()."/img/familias/101.jpg'>";

the browser shows de image correctly.

What is wrong in my code? I want to check if the file exists with the relative route.

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

检查zend框架2中是否存在文件时出现问题: < p>检查时:

  is_file(“/ usr / local / zend / apache2 / htdocs / my_viena / panel / public / img / familias / 101.jpg”)



  is_file($ this-&gt; basePath()。“/ img / familias / 101.jpg”)

这是从... 模块,它返回false。


  echo“&lt; img src ='”。$ this-&gt  ; basePath()。“/ img / familias / 101.jpg'&gt;”; 

浏览器正确显示图像。 \ n

我的代码有什么问题? 我想检查文件是否存在相关路径。

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

1条回答 默认 最新

  • dsieyx2015 2014-12-15 14:21

    In one situation $this->basePath() will return and empty string. And when checking if your file exists it will search for the absolute path /img/familias/101.jpg

    echo "<img src='".$this->basePath()."/img/familias/101.jpg'>"; will show the image because it will load something like this

    public/img/familias/101.jpg works because everything in zf2 is realtive to the public folder (I think)

    side note don't use echo for creating your tags

    打赏 评论

相关推荐 更多相似问题