CodeIgniter Forums
read_file, file_exists return nothing - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: read_file, file_exists return nothing (/showthread.php?tid=11525)



read_file, file_exists return nothing - El Forum - 09-11-2008

[eluser]Unknown[/eluser]
so I was trying to use read_file to check if a file exist ... but it returned nothing rather the file existed or not ... so I decided to just use php's file_exists ... it still returns nothing ... can someone help? I am trying to see if an image exist ... if it does show it ... else show some other code. This is what I have:

Code:
<?
$filename = "http://completebeautylist.com/uploads/image_".$this->session->userdata('company').".jpg";
if(file_exists($filename)){?>
  <img src="&lt;?=$filename?&gt;" />
&lt;?}else{?&gt;
<div class="img"><strong>Logo</strong> or Ad Image</div>
&lt;?}?&gt;



read_file, file_exists return nothing - El Forum - 09-11-2008

[eluser]richthegeek[/eluser]
Try trim()ing the session data.

if you are still having trouble try using scandir to see what files actually exist in that directory from a PHP-visible perspective


read_file, file_exists return nothing - El Forum - 09-12-2008

[eluser]Sumon[/eluser]
From php manual
Code:
&lt;?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
    echo "The file $filename exists";
} else {
    echo "The file $filename does not exist";
}
?&gt;
it mean here is a path of server path (i mean /path/to/) not browser path (i mean
http://completebeautylist.com/). So would you please give a try as
Code:
&lt;?
$filename = "/path/to/image/".$this->session->userdata('company').".jpg";
if(file_exists($filename)){?&gt;
  <img src="&lt;?=$filename?&gt;" />
&lt;?}else{?&gt;
<div class="img"><strong>Logo</strong> or Ad Image</div>
&lt;?}?&gt;
where /path/to/image/ is your server path for image.


read_file, file_exists return nothing - El Forum - 09-12-2008

[eluser]attos[/eluser]
Did you mean readfile() instead of read_file()?

I had the same problem with readfile() returning an empty file (zero length). I solved it using:

Code:
$fp = fopen($path, 'rb');
fpassthru($fp);

readfile() worked in my development environment (WinXP + xampp), but failed under FreeBSD and Apache.