Re: is_readable(http://.... text file) says not, but I canin browser

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



John Allsopp wrote:
Nathan Nobbe wrote:
On Sun, Dec 28, 2008 at 11:02 AM, John Allsopp <john@xxxxxxxxxxxxxxxxx>wrote:

Hi

I'm sure this is simple for yous all but I'm not sure I know the answer.

      $myFileLast = "http://www.myDomain.com/text.txt";;
      if (is_readable($myFileLast))
      {
          $fh = fopen($myFileLast, 'r');
          $theDataLast = fread($fh, 200);
          fclose($fh);
          echo ("The dataLast: ".$theDataLast."<br>\n");
      } else
      {
          echo ("Last fix file unavailable: $myFileLast<br>\n");
      }

returns Last fix file unavailable even for a file that my browser can read.
All I want to do is skip over files

This could be a very simple error, I'd appreciate a pointer. Is it
permissions being different for PHP versus the browser or something? PHP is
running on a different server.


are you basically trying to tell if theres a resource @ the given url? if
so, id prefer curl myself.

something like

if(($ch = curl_init($url) === false)
  echo ("Last fix file unavailable: $myFileLast<br>\n");
else {
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);*
*  $theDataLast = curl_exec($ch);
  echo ("The dataLast: ".$theDataLast."<br>\n");*
*  curl_close($ch);*
*}

obviously, youll need the curl extension installed for this to work. i know the fopen wrappers will allow you to get a read-only handle to an http url, but im not sure what is_readable() will do w/ that, it may be limited to the
local filesystem.

-nathan

Thanks. I'm trying to read the contents of the file at the URL, but it might not exist.

So far I'm getting a lot of *Warning*: curl_setopt(): supplied argument is not a valid cURL handle resource in */home/myAcc/public_html/test.php* on line *58
*
I searched phpinfo for 'curl' and it came up nothing, so I'm just checking with my hosts to see if I have the extension installed.

I'll be back, thanks
J

might be a bracket thing..

could try:
if( ($ch = curl_init($url)) === false) {
  echo ("Last fix file unavailable: $myFileLast<br>\n");
} else {
....

or
if( !is_resource($ch = curl_init($url)) ) {
  echo ("Last fix file unavailable: $myFileLast<br>\n");
} else {
....

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux