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 に答える