douxidang9092 2014-12-15 12:59
浏览 31
已采纳

is_file和zend框架路由

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

When checking:

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

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

When checking:

is_file($this->basePath()."/img/familias/101.jpg")

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.

  • 写回答

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 www.yoursite.com/img/familias/101.jpg

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog