Reply to Re: fopen( )

Your name:

Reply:


Posted by Rik on 01/17/07 00:02

rfhurley wrote:
> I'm a newbie at this... I'm trying to run a PHP script from the W3C
> PHP tutorial, and the example shows the following code:
>
> <html>
> <body>
>
> <?php
> $file=fopen("welcome.txt","r");
>>
>
> </body>
> </html>
>
> I have a file in that directory labeled welcome.txt (with some text,
> of course), but when I open the sample file (labeled fileOpen.php) in
> the browser, it brings up a blank page (with no error message). I've
> been working through the rest of the tutorial OK, and I know my web
> host supports PHP, so my question is: What is this function supposed
> to do? Bring up the text file in the browser? or open it in Notepad?
> Do I need to combine it with another command to make it do anything?
>
> Sorry if this is a stupid question. As I said, I'm new at this, but I
> haven't had any trouble getting my scripts to work until now.

http://www.php.net/fopen

fopen() returns a resource (in essence a 'link' to the file), not the
actual contents.

Furthermore, you don't output anything to the browser, you just tell php to
open a file, and then.... nothing.

Following a fopen() is usually an fread() <http://www.php.net/fread>, and
to output stuff to the browser something like 'echo' or 'print' is used.
PHP cannot control your computer (i.e. open Notepad), it can only perform
actions on the server it runs on, and report back, usually to a browser by
http.

To get the contents of welcome.txt in your html page, you could include()
or require() it, you could use file_get_contents()/readfile() (essentially
a shortcut for fopen() & fread()) in combination with an echo, and several
other options.
--
Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация