![]() |
PHP Checking if URL/File Exists... Return True/False
Code:
<?php if(file_exists("http://www.site.com/images/$id/misc6.jpg")){ DO THIS }?> EDIT: Note... $id is assigned above this statement. |
Bumpity Bump
|
file_exists doesn't support checks on remote files.
why not just try with fopen ? |
also make sure
allow_url_fopen is enabled (Dirty D has chicks in the pool on Labor Day, why am I commenting on someone else's code?) |
Quote:
|
The most secure way to accomplish what you need is using cURL.
Many will argue that enabling URL wrappers is a potential security risk within PHP. Just google and you'll find many articles. This is why that option is turned off by default in the configuration file. |
if the file is an image every time... you can use getimagesize >> http://us2.php.net/getimagesize
Code:
Example #3 getimagesize (URL) |
Quote:
|
allow_url_include doesn't work unless allow_url_fopen is enabled, buddy.
|
Quote:
|
|
This is incredibly basic shit. The following is a top-down-no-classes-used example, using cURL, as suggested above. Note the lack of RETURNTRANSFER as we're only checking the status code.
Code:
$ch = curl_init(); Quote:
|
Quote:
This is how I would use it. Code:
$file_url = "http://www.site.com/images/{$id}/misc6.jpg"; |
Quote:
|
should have been:
Code:
$file_url = "http://www.site.com/images/{$id}/misc6.jpg"; |
$yourfile = "full/path/to/your/file.php-jpg-gif-whatever" ;
IF (file_exists($yourfile)) { print "Your File Does Existst" ; // TRUE } ELSE { print "Your file Doesn't exists" ; // FALSE } |
I ran into this issue long ago, but I think I solved it by realising that both domains I was working with were on the same server, doh!
Good luck. |
Quote:
|
Quote:
|
Jeeesus peoples. This is a hack of a slightly-better-than-my-above for just checking for the files' existence, based upon code at PHP.net; I figured this thread should die a horrible death, so here ya go.
Code:
function http_file_exists($url=FALSE) { Code:
$urltest = array ("http://www.google.com/logo.gif", "http://www.google.com/intl/en_ALL/images/logo.gif"); Code:
http://www.google.com/logo.gif is a 404. |
Quote:
|
Quote:
|
Quote:
|
Quote:
...and I'm gonna keep using a banned imagehost until this damn thing goes away. S'there! |
Quote:
Imageshack works on gfy.com, fail. |
Quote:
LOS GROUCHY KICK YOUR FACE LOS GROUCHY http_file_exists() IN TO OUTER SPACE Dammit. It used to be banned as far back as.. two weeks ago. |
|
Quote:
LOS GROUCHY NO HURT LOS GROUCHY http_file_exists() RETURN ERROR FOR SUCKAGE Hmm, weird, that little smiley you posted from imageshack showed for me on gfy.com |
Quote:
Feel that burn, motherbitch. Feel it!? Mmmyeah. That's the stuff. |
return (!file_get_contents('URL')?false:true);
Do I win ? |
Quote:
You win this time my little pretty, but I will get you and your dog too! |
Quote:
Quote:
|
Quote:
|
|
Quote:
|
Quote:
|
All times are GMT -7. The time now is 03:07 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123