Jump to content

Archived

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

slipperyfish

File exists not working

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

Share this post


Link to post
Share on other sites
[code=php:0]
if (file_exists(trim($thesrc))) {
[/code]

Share this post


Link to post
Share on other sites
Unfortunately, adding the trim function didn't work. it will says: "Invalid Image Source".

Anybody any more ideas why it's does that?

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.