Jump to content


Photo

File exists not working


  • Please log in to reply
4 replies to this topic

#1 slipperyfish

slipperyfish
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 05 July 2006 - 01:33 AM

I have a fairly simple scirpt to check if an image exists, then give back some feedback:


<?php

print '<br />';
print '<center>';

$thesrc = $_GET['src'];

If (file_exists($thesrc)) {

	print '<font face="Tahoma" size="2">Valid image source</font>';
	print '<br /><br />';
	print '<img src="' .$thesrc. '" />';

} else {

	print '<br />';
	print '<center>';
	print '<font face="Tahoma" size="2">Invalid image source</font>';

}

print '</center>';

?>


.. but this just always reutnrs false... and suggestions :S ??

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 05 July 2006 - 02:11 AM

if (file_exists(trim($thesrc))) {


#3 slipperyfish

slipperyfish
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 05 July 2006 - 09:01 AM

Unfortunately, adding the trim function didn't work. it will says: "Invalid Image Source".

Anybody any more ideas why it's does that?

#4 slipperyfish

slipperyfish
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 05 July 2006 - 09:17 AM

___Sorry, just trying to get this seen___

#5 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 05 July 2006 - 09:34 AM

file_exists only works within your own site and cannot include http://blah.com

so use this instead

<?php

print '<br />';
print '<center>';

$thesrc = $_GET['src'];

if( parse_url( $thesrc ) )
{
	print '<font face="Tahoma" size="2">Valid image source</font>';
	print '<br /><br />';
	print '<img src="' .$thesrc. '" />';
}
else
{
	print '<br />';
	print '<center>';
	print '<font face="Tahoma" size="2">Invalid image source</font>';
}

print '</center>';

?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users