Jump to content

files_exists() question


ballhogjoni

Recommended Posts

use php.net for refrences ok mate..........

 

 

file_exist needs the server path..........

<?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
   echo "The file $filename exists";
} else {
   echo "The file $filename does not exist";
}
?>

 

 

useing headers can see if the file exist via a full external url...

 

<?php
$file = 'http://www.domain.com/somefile.jpg';
$file_headers = @get_headers($file);
if($file_headers[0] == 'HTTP/1.1 404 Not Found') {
   $exists = false;
}
else {
   $exists = true;
}
?>

Link to comment
Share on other sites

I am not familiar with the term "filesystem path", is that another term for absolute path?

 

Yeah sorry, my bad. You could probably lose the filesystem part.

 

use php.net for refrences ok mate..........

 

maybe you ought take your own medicine. file_exists() works perfectly well given a url providing the correct wrappers are installed and enabled.

Link to comment
Share on other sites

thx,

 

all that being said I have the following code that does not work. I am on shared hosting so I don't know which wrappers are on and which ones are off (is there a way to tell?).

 

$flag_image = ABSOLUTE_PATH."public_html/xxxxxx/articles/images/flags/". $myrow['flag']. ".gif";
		echo $flag_image;
		if (file_exists($flag_image)) {
			$size = getimagesize($flag_image);
			echo " <img src='" . FACS_href . "articles/images/flags/" . $myrow['flag']. ".gif' " . $size[3] . " alt=''/>";
		}

 

the script will echo the $flag_image but the script dies after that, I assume this means that file_exists is not working correctly. Any advice?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.