![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
♥ ♦ ♣ ♠
Industry Role:
Join Date: Sep 2002
Location: Porn Valley, CA
Posts: 10,590
|
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.
__________________
![]() ![]() ![]() "I'm selflessly supporting the common good, but only coincidentally looking out for No.1." |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
♥ ♦ ♣ ♠
Industry Role:
Join Date: Sep 2002
Location: Porn Valley, CA
Posts: 10,590
|
Bumpity Bump
__________________
![]() ![]() ![]() "I'm selflessly supporting the common good, but only coincidentally looking out for No.1." |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Industry Role:
Join Date: Jun 2004
Location: New York, NY
Posts: 6,890
|
file_exists doesn't support checks on remote files.
why not just try with fopen ?
__________________
Skype variuscr - Email varius AT gmail |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: May 2002
Location: Paying Webmasters Millions Since 1999
Posts: 4,044
|
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?)
__________________
![]() Dirty D - ICQ #1326843 - $1 Million Dollars of Bonus Money - 8,000+ FHG! Glory Hole Girlz - Crack Whore Confessions - Tampa Bukkake - Slut Wife Training - Fuck a Fan Electricity Play - Porn Video Drive - Theater Sluts - Skunk Riley - Ukraine Amateurs - Strapon Sessions |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
Viva la vulva!
Join Date: Mar 2003
Location: you can't please everyone, so you got to please yourself
Posts: 16,557
|
Quote:
Shrinkage ![]() |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Join Date: May 2004
Location: SW Palm Bay, Florida
Posts: 1,323
|
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.
__________________
subarus. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
if the file is an image every time... you can use getimagesize >> http://us2.php.net/getimagesize
Code:
Example #3 getimagesize (URL) <?php $size = getimagesize("http://www.example.com/gifs/logo.gif"); // if the file name has space in it, encode it properly $size = getimagesize("http://www.example.com/gifs/lo%20go.gif"); ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Join Date: May 2004
Location: SW Palm Bay, Florida
Posts: 1,323
|
allow_url_include doesn't work unless allow_url_fopen is enabled, buddy.
__________________
subarus. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Confirmed User
Industry Role:
Join Date: Apr 2006
Location: Germany
Posts: 4,323
|
![]()
__________________
--- ICQ 14-76-98 <-- I don't use this at all |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 | |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
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(); curl_setopt($ch, CURLOPT_URL,"http://www.site.com/blah/"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch,CURLOPT_VERBOSE, FALSE); curl_setopt($ch, CURLOPT_TIMEOUT, 5); $pageData=curl_exec($ch); $statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); switch ($statusCode) { case 404: filemissing()... break; case 401: authreq(); break; default: whatev(); } Quote:
__________________
Last edited by GrouchyAdmin; 09-08-2009 at 09:18 AM.. Reason: getinagesize() is bad for all living things |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#13 | |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
Quote:
This is how I would use it. Code:
$file_url = "http://www.site.com/images/{$id}/misc6.jpg"; $file_exists = is_array($file_url); |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#14 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
Generally, lazily coded image hosting scripts. The easiest way to abuse this I've actually seen in the wild. It starts with a valid GIF header, and has a PHP script as the payload. WIthout giving away too many details, file naming conventions and autonegotiation can cause you bigtime issues.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#15 |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
should have been:
Code:
$file_url = "http://www.site.com/images/{$id}/misc6.jpg"; $file_exists = is_array(getimagesize($file_url)); |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#16 |
Registered User
Industry Role:
Join Date: Aug 2003
Location: QWEBEC Corporate Office
Posts: 7,124
|
$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 } |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#17 |
Porn Meister
Industry Role:
Join Date: Feb 2005
Posts: 16,443
|
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.
__________________
43-922-863 Shut up and play your guitar. ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#18 |
Guest
Posts: n/a
|
|
![]() ![]() ![]() ![]() ![]() |
![]() |
#19 |
Confirmed User
Join Date: Apr 2009
Posts: 1,319
|
I don't even think he read the thread.
__________________
History will be kind to me for I intend to write it. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#20 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
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) { // Bad URL, bail. if (!(@parse_url($url))) return FALSE; // No cURL, bail. if (!(function_exists('curl_init'))) return FALSE; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_setopt($ch, CURLOPT_FAILONERROR, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); return (curl_exec($ch) !== FALSE) ? TRUE : FALSE; } Code:
$urltest = array ("http://www.google.com/logo.gif", "http://www.google.com/intl/en_ALL/images/logo.gif"); foreach ($urltest as $url) { echo http_file_exists($url) ? "$url exists.\n" : "$url is a 404.\n"; } exit; Code:
http://www.google.com/logo.gif is a 404. http://www.google.com/intl/en_ALL/images/logo.gif exists.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#21 |
Confirmed User
Industry Role:
Join Date: Mar 2004
Location: Rock Hill, SC
Posts: 5,370
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#22 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#23 | |
Guest
Posts: n/a
|
Quote:
|
|
![]() ![]() ![]() ![]() ![]() |
![]() |
#24 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
I cutchoo mang. I cutchoo so bad you wish I no cutchoo.
![]() ...and I'm gonna keep using a banned imagehost until this damn thing goes away. S'there!
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#25 | |
Guest
Posts: n/a
|
Quote:
Imageshack works on gfy.com, fail. |
|
![]() ![]() ![]() ![]() ![]() |
![]() |
#26 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
LOS GROUCHY KICK YOUR ASS
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.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#27 |
Do Fun Shit.
Industry Role:
Join Date: Dec 2004
Location: OC
Posts: 13,393
|
![]()
__________________
![]() “I have the simplest tastes. I am always satisfied with the best.” -Oscar Wilde |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#28 | |
Guest
Posts: n/a
|
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 |
|
![]() ![]() ![]() ![]() ![]() |
![]() |
#29 | |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
Quote:
Feel that burn, motherbitch. Feel it!? Mmmyeah. That's the stuff.
__________________
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#30 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
return (!file_get_contents('URL')?false:true);
Do I win ? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#31 |
Guest
Posts: n/a
|
|
![]() ![]() ![]() ![]() ![]() |
![]() |
#32 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
No. Michael P wins for 'not reading the fucking thread at all', but nice try.
Surrender Grouchy, my ass.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#33 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
Damnit .
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#34 |
Do Fun Shit.
Industry Role:
Join Date: Dec 2004
Location: OC
Posts: 13,393
|
![]()
__________________
![]() “I have the simplest tastes. I am always satisfied with the best.” -Oscar Wilde |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#35 |
Now choke yourself!
Industry Role:
Join Date: Apr 2006
Posts: 12,085
|
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#36 |
Confirmed User
Join Date: Feb 2002
Location: ICQ: 251425 Fr/Au/Ca
Posts: 6,863
|
If you cram it aaaalllll onto one line, if the script ever breaks, at least you know the line to debug
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |