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.

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

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

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

这是我计算机中的绝对路径,它返回true。

检查时:

  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 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

    打赏 评论

相关推荐 更多相似问题