Welcome Guest, Not a member yet? Register   Sign In
read_file, file_exists return nothing
#1

[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;
#2

[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
#3

[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.
#4

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




Theme © iAndrew 2016 - Forum software by © MyBB