Jump to content

File exists not working


slipperyfish

Recommended Posts

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

[code]

<?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>';

?>

[/code]

.. but this just always reutnrs false... and suggestions :S ??
Link to comment
https://forums.phpfreaks.com/topic/13692-file-exists-not-working/
Share on other sites

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

so use this instead

[code]<?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>';

?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.