Page 1 of 1

PHP - Checking if a remote file exists

Posted: Wed Jun 04, 2003 10:11 am
by boycee

Code: Select all

if ($type == "Logos")
{
   if (fopen "http://images.custommobile.com/image_files/'.$page.'.gif", "r") == false)
   {
      echo 'INCORRECT';
   }
   else
   {
      echo '<img src="http://images.custommobile.com/image_files/'.$page.'.gif" />';
   &#125;
&#125;
Am i on the right track.

Posted: Wed Jun 04, 2003 4:38 pm
by delorian
Try this modification:

Code: Select all

if ($type == "Logos") 
&#123; 
   if (@fopen("http://images.custommobile.com/image_files/".$page.".gif", "r"))
   &#123;  
     echo '<img src="http://images.custommobile.com/image_files/".$page.".gif" />'; 

   &#125; 
   else  &#123;       echo 'INCORRECT';    &#125; 
&#125;
But the allow_url_fopen directive MUST be set to ON in your php.ini if you want to open a file using fopen with protocol. http://pl.php.net/manual/en/ref.filesys ... -url-fopen

Posted: Wed Jun 04, 2003 5:01 pm
by boycee
i tried the code you suggested, and it still just hangs.

What you mean php.ini ?
I dont understand what you mean by this file.

Thanks for the help so far.

Posted: Thu Jun 05, 2003 1:15 am
by delorian
php.ini is the PHP confiugration file. Probably you don't have access to it on your web serwer (or maybe you have if its yours :D), so if you want to see if allow_url_open is set see the phpinfo()'s PHP Core section.

Just make a script with code:

Code: Select all

<?php phpinfo(); ?>
and use it.

BTW: Visit http://php.net , it's a great knowledge library :D

Posted: Thu Jun 05, 2003 6:43 am
by detrox
I am puzzled. If I can fopen a remote file, can I read it by fread? If I can read it then how about to read a .php file.

And I do not catch the '@fopen'. What does it mean? I can not find it in PHP Manual.

Posted: Thu Jun 05, 2003 9:13 am
by delorian
detrox wrote:I am puzzled. If I can fopen a remote file, can I read it by fread? If I can read it then how about to read a .php file.
Yes, you will open the .php file, and you will recieve the parsed content, the same that you get when visiting the page... I think so, I've tried this some time ago, and it worked like this.
detrox wrote: And I do not catch the '@fopen'. What does it mean? I can not find it in PHP Manual.
Probably you didn't search good enough :D. @ silences error messages generated by functions.

Thanks, delorian.

Posted: Thu Jun 05, 2003 9:48 am
by detrox
Thanks, delorian. I got it. But for my poor searching ability, I still can not find it in my manual. I try '@','operator','silence error message' but these do not work.
:oops: :oops:

Posted: Thu Jun 05, 2003 10:40 am
by twigletmac
Hi, the manual calls the @ sign an 'error control operator':
http://php.net/manual/language.operator ... ontrol.php

Mac