Re: [PHP] output of fread() is blank

2003-01-27 Thread Jason Sheets
Hello,

The PHP manual page for filesize
(http://www.php.net/manual/en/function.filesize.php) mentions that it
will not work on remote files.  fread will stop once n number of bytes
are read or EOF is received so you could set this to the maximum file
size (in bytes) that you want to download.

Jason

On Mon, 2003-01-27 at 16:27, Guru Geek wrote:
 Hello,
 
 I'm a recent convert from CGI/Perl and so am still getting my feet wet
 in PHP.
 
 Here's my code:
 $filename = http://www.myserver.com/include/sometext.txt;;
 $handle = fopen ($filename, rb);
 $contents = fread ($handle, filesize ($filename));
 fclose ($handle);
 echo $contents;
 exit;
 
 The problem is nothing shows up, it's a blank browser window.  I'm sure
 this is a stupid questions and very easily fixed.
 
 Also, if the text file I'm trying to read is multi lined, shouldnt I be
 placing the contents into an array?  or is that old cgi habits coming
 through?
 
 Thanks,
 Roger
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


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




Re: [PHP] output of fread() is blank

2003-01-27 Thread Philip Olson

On Mon, 27 Jan 2003, Guru Geek wrote:

 Hello,
 
 I'm a recent convert from CGI/Perl and so am still getting my feet wet
 in PHP.
 
 Here's my code:
 $filename = http://www.myserver.com/include/sometext.txt;;
 $handle = fopen ($filename, rb);
 $contents = fread ($handle, filesize ($filename));
[snip]

See:
  http://www.php.net/filesize

You cannot use it with urls.  Also if you can help it, 
don't go through http like this.  But anyway, see
also: file(), fgets(), and include()

Regards,
Philip


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




Re: [PHP] output of fread() is blank - FIXED

2003-01-27 Thread Guru Geek
Here's my code now:

$filename =
/usr/local/plesk/apache/vhosts/myserver.com/httpdocs/include/text.txt;
$handle = fopen ($filename, r);
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
echo readfile($filename);
exit;

now it displays the contents of the text.txt file.  I originally had just
/include/text.txt but it told me no such file existed.  But once I added the
root directory stuff in front of that, it works.

I'm having a similar problem getting smarty to run, it keeps telling me that
it can't find index.tpl and now I think I know what the problem is...

Thanks to everyone



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




Re: [PHP] output of fread() is blank - FIXED - updated

2003-01-27 Thread Guru Geek
Sorry, here is the code now ( I need a nap )

$filename
=/usr/local/plesk/apache/vhosts/myserver.com/httpdocs/include/text.txt;
$handle = fopen ($filename, r);
$contents = fread ($handle, filesize ($filename));
fclose ($handle);
echo $contents;
exit;



Guru Geek wrote:

 Here's my code now:

 $filename =
 /usr/local/plesk/apache/vhosts/myserver.com/httpdocs/include/text.txt;
 $handle = fopen ($filename, r);
 $contents = fread ($handle, filesize ($filename));
 fclose ($handle);
 echo readfile($filename);
 exit;

 now it displays the contents of the text.txt file.  I originally had just
 /include/text.txt but it told me no such file existed.  But once I added the
 root directory stuff in front of that, it works.

 I'm having a similar problem getting smarty to run, it keeps telling me that
 it can't find index.tpl and now I think I know what the problem is...

 Thanks to everyone

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



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




Re: [PHP] output of fread() is blank - FIXED - updated

2003-01-27 Thread Philip Olson
On Mon, 27 Jan 2003, Guru Geek wrote:

 Sorry, here is the code now ( I need a nap )
 
 $filename
 =/usr/local/plesk/apache/vhosts/myserver.com/httpdocs/include/text.txt;
 $handle = fopen ($filename, r);
 $contents = fread ($handle, filesize ($filename));
 fclose ($handle);
 echo $contents;
 exit;

For something like this, just use readfile() and not fread 
as it'd be much more efficient if you don't actually manipulate 
the string $contents.  So:

  readfile($filename);  // note: do not use echo

Also, what is your include_path setting?  It's important
you know it and what it means as that'll answer the
question in your last post:

  print ini_get('include_path');
  http://www.php.net/manual/configuration.directives.php#ini.include-path

Also, no need for exit here as that happens automatically.

Regards,
Philip


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




Re: [PHP] output of fread() is blank - FIXED - updated

2003-01-27 Thread Guru Geek
In all actuality I will be manipulating the information that is in that file.

I'm trying to build a log in script.  The id's and passwords are stored in a
text file.  I'm trying to read that text file so I can compare what the
user/viewer had typed in the id and password boxes.  I'm so new to PHP I'm
taking it in baby steps...

Philip Olson wrote:

 On Mon, 27 Jan 2003, Guru Geek wrote:

  Sorry, here is the code now ( I need a nap )
 
  $filename
  =/usr/local/plesk/apache/vhosts/myserver.com/httpdocs/include/text.txt;
  $handle = fopen ($filename, r);
  $contents = fread ($handle, filesize ($filename));
  fclose ($handle);
  echo $contents;
  exit;

 For something like this, just use readfile() and not fread
 as it'd be much more efficient if you don't actually manipulate
 the string $contents.  So:

   readfile($filename);  // note: do not use echo

 Also, what is your include_path setting?  It's important
 you know it and what it means as that'll answer the
 question in your last post:

   print ini_get('include_path');
   http://www.php.net/manual/configuration.directives.php#ini.include-path

 Also, no need for exit here as that happens automatically.

 Regards,
 Philip



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