Page 1 of 1

remote file exist help

Posted: Thu Jan 29, 2004 4:37 am
by Tecktron
Hi,
I'm trying to check to see if a file that a user is pointing to exists or not, on a remote password protected secure site.

I copied this piece of code from php.net but it doesn't seem to be working for me and I was wondering if I need todo anything else to get it working or am I just burned. Also any alternatives to finding if a remote file exists or not would also be very helpful.
Copied Code:

Code: Select all

if (@fclose(@fopen('http://www.example.com', 'r'))) { 
     print('File exists.'); 
} else { 
     print('File does not exist.'); 
}

Seems like it should work but not for me.

My Code:

Code: Select all

$file = 'HTTPS://user:pass@example.com/images/img.jpg';
if (@fclose(@fopen($file, 'r'))) { //remote file exist
     print('File exists.'); 
} else { 
     print('File does not exist.'); 
}
Now I know that the file exists because I put it there and if I enter the text provided in $file into my browser I get the file. But no! I get this error everytime:
Warning: fopen(HTTPS://...@example.com/images/img.jpg): failed to open stream: No such file or directory in /home/me/www/fileexist.php on line **
Warning: fclose(): supplied argument is not a valid stream resource in /home/me/www/fileexist.php on line **
File does not exist.
I've added php_flag allow_url_fopen on in my .htaccess file incase my server has it turned off, but no luck. Did Check the phpinfo output and it says it's on locally and master, so is there something else I'm missing?

PLEASE HELP!

Thanks in advance!
--Tecktron

Posted: Thu Jan 29, 2004 5:07 am
by JayBird
quotes from the manual
It seems that fopen() errors when you attempt opening a url starting with HTTP:// as opposed to http:// - it is case sensitive. In 4.3.1 anyway..."HTTP://", by not matching "http://" will tell the wrapper to look locally. From the looks of the source, the same goes for HTTPS vs https, etc.
Playing with fopen("https://xxx", "r") it seems that HTTPS is only supported with OpenSSL AND PHP 4.3 . Older versions of PHP don't seem to be able to do this.
Maybe some help!?

Mark