0

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

4

1 回答 1

4

这很可能是相对路径问题。您可能想尝试更绝对的路径:

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

显然,您正确地提供了文档根目录的路径。如果您不确定那是什么,只需var_dump($_SERVER['DOCUMENT_ROOT']);将其与您相信或验证的上传路径进行比较。

于 2013-01-09T02:32:46.933 回答