There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen boot computer connection crash css dell display driver drivers email error ethernet excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware monitor network networking nvidia outlook outlook 2003 outlook express partition password printer problem router slow software sound trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
fopen is wierd ...


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
bob121's Avatar
Senior Member with 188 posts.
 
Join Date: Sep 2006
01-Jul-2008, 02:35 PM #1
fopen is wierd ...
I am having a rather weird problem on my VPS.

The FOpen Function isn't working correctly.


This is the URL to the PHP document which is reading the text file
http://yshout.northeast-networks.net/test.php

This is the text file the PHP reads
http://yshout.northeast-networks.net/log.txt

This is not the attucally script i am having the problem with, This is just to represent the problem.

James.
cpscdave's Avatar
Senior Member with 281 posts.
 
Join Date: Feb 2004
Experience: Intermediate
02-Jul-2008, 11:21 AM #2
how are you using the fopen command?

Generally the way I do it is:
PHP Code:
$theFile "/some/path/log.txt";
$fp fopen($theFile"r");
$content fread($fpfilesize($theFile));
print 
"$content"
tried it out on your file and worked for me
Big-K's Avatar
Distinguished Member with 6,883 posts.
 
Join Date: Nov 2003
Location: Kansas
Experience: Advanced
04-Jul-2008, 04:01 PM #3
you can also look into file_get_contents()
TheRobatron's Avatar
Computer Specs
Senior Member with 465 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
07-Jul-2008, 06:09 PM #4
Quote:
Originally Posted by Big-K View Post
you can also look into file_get_contents()
And here's the function if your version of PHP doesn't support it:

PHP Code:
<?PHP
if (!function_exists('file_get_contents')) {
      function 
file_get_contents($filename$incpath false$resource_context null)
      {
          if (
false === $fh fopen($filename'rb'$incpath)) {
              
trigger_error('file_get_contents() failed to open stream: No such file or directory'E_USER_WARNING);
              return 
false;
          }
 
          
clearstatcache();
          if (
$fsize = @filesize($filename)) {
              
$data fread($fh$fsize);
          } else {
              
$data '';
              while (!
feof($fh)) {
                  
$data .= fread($fh8192);
              }
          }
 
          
fclose($fh);
          return 
$data;
      }
  }
?>
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,715 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
07-Jul-2008, 07:33 PM #5
You can define functions "on-the-fly" like that? neat.

Peace...
TheRobatron's Avatar
Computer Specs
Senior Member with 465 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
08-Jul-2008, 04:58 AM #6
Not quite It's a function I use a lot for one of my sites because the web server doesn't support get_file_contents(). I think it's on php.net somewhere.
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
08-Jul-2008, 06:29 AM #7
Quote:
Originally Posted by tomdkat View Post
You can define functions "on-the-fly" like that? neat.

Peace...
Yeah, of course.

http://www.php.net/manual/en/functio...ents.php#80435
TheRobatron's Avatar
Computer Specs
Senior Member with 465 posts.
 
Join Date: Oct 2007
Location: England
Experience: Intermediate
08-Jul-2008, 07:43 AM #8
That's where I found it I knew it was there somewhere.

It's the one above though:

http://www.php.net/manual/en/functio...ents.php#80707
MMJ's Avatar
MMJ MMJ is offline
Distinguished Member with 3,250 posts.
 
Join Date: Oct 2006
08-Jul-2008, 08:59 AM #9
Quote:
Originally Posted by TheRobatron View Post
That's where I found it I knew it was there somewhere.

It's the one above though:

http://www.php.net/manual/en/functio...ents.php#80707
Opps, must have copied the wrong link.
tomdkat's Avatar
Computer Specs
Distinguished Member with 3,715 posts.
 
Join Date: May 2006
Location: S.F. Bay Area, CA
Experience: Intermediate
08-Jul-2008, 10:53 AM #10
Thanks guys. This is the link I needed.

I didn't know PHP had this functionality. Neat.

Peace...
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:14 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.