file_exists()无法正常工作 [英] file_exists() not working codeigniter

查看:61
本文介绍了file_exists()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与Codeigniter合作.我要显示图像,但如果不存在某些图像,则应显示 image-not-found-medium.jpg 这是虚拟图像.

I am working with codeigniter. I want to display images but if some image is not exist it should show image-not-found-medium.jpg which is dummy image..

下面是我的代码

<?php
    $image_path_medium = site_url('assets/images-products/medium');
    $image_not_found_medium =  $image_path_medium . "/" . "image-not-found-medium.jpg";
    $image_name_with_path = $image_path_medium . "/" . $home_technology[$key]->product_sku . "-" . "a" . "-medium.jpg";

    if (file_exists($image_name_with_path)) {
        echo $image_name_with_path;
    } else {
        echo $image_not_found_medium;
    }
    ?>

但它始终显示 $ image_not_found_medium ,我认为我的 if条件存在问题.请帮忙.

but it always shows $image_not_found_medium i think there is problem with my if condition. Please help.

推荐答案

<?php
    $image_path_medium = site_url('assets/images-products/medium');
    $image_not_found_medium =  $image_path_medium . "/" . "image-not-found-medium.jpg";
    $image_name_with_path = $image_path_medium . "/" . $home_technology[$key]->product_sku . "-" . "a" . "-medium.jpg";//this is your image url
    $image_file_path=FCPATH.'assets/images-products/medium'. $home_technology[$key]->product_sku . "-" . "a" . "-medium.jpg";//this is your file path

   if (file_exists($image_file_path)) //file_exists of a url returns false.It should be real file path
   {
       echo $image_name_with_path;
   } 
   else 
   {
      echo $image_not_found_medium;
   }
?>

这篇关于file_exists()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆