【问题标题】:Smarty foreach loop and file_existSmarty foreach 循环和 file_exist
【发布时间】:2015-10-08 16:06:08
【问题描述】:

我正在使用Smarty php template engine,并且正在尝试使用$id_attribute 名称验证.jpg 图像的存在:

{foreach from=$product.colors key='id_attribute' item='color'}
    {if file_exists($img_col_dir|cat:$id_attribute|cat:'.jpg')} 
        yes 
    {else} 
        no 
    {/if}

$img_col_dir 是“http://www.domain.com/img/co/”,$id_attribute 是一个数字。许多文件以 .jpg 格式存在,但整个循环没有找到任何东西,返回“no”。我做错了什么?

【问题讨论】:

    标签: php foreach smarty php-extension file-exists


    【解决方案1】:

    您无法检查 url 上的文件是否存在,

    http://www.domain.com/img/co/myfile.jpg
    

    仅在您的本地驱动器上

    c:\myfolder\myimages\myfile.jpg
    

    另外,您应该在您的 php 文件中执行此逻辑,而不是在您的 smarty 模板中。

    检查文件是否存在,然后为每个图像传递一个 smarty 变量 image_exists。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-11
      相关资源
      最近更新 更多