dsh12544 2013-01-09 02:29
浏览 25

PHP file_exists()无法正常工作[关闭]

I have read some of the answered question here at stackoverflow which is quiet related to my problem but still I can't figure out what's wrong with my code. It does not check if the file already exist it only returns the default image even there is an existing file in my uploads folder. This is my first time to use file_exists() I'm not really familiar with this code.

here is my code:

<?php $filename = 'uploads/';?>
<?php if(file_exists($filename)) {?>
<img src='<?php  echo base_url();?>uploads/' width='180' height='200'  id="images"name='images' />

<?php } else { ?>

<img src='<?php echo base_url();?>assets/images/no_image.jpg' width='180' height='200' id="images" name='images' />
<?php } ?>

Thanks for any help..

  • 写回答

1条回答 默认 最新

  • duankua3620 2013-01-09 02:32
    关注

    It's most likely a relative path issue. You may want to try a more absolute path:

    <?php $filename = $_SERVER['DOCUMENT_ROOT'].'/my_site/uploads/';?>
    

    Where obviously you provide the path from the document root correctly. If you're not sure what that is, just var_dump($_SERVER['DOCUMENT_ROOT']); and compare that to the path you believe or verify for uploads.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制