fopen

This is a discussion on fopen within the PHP General forums, part of the PHP Programming Forums category; Hello, I am trying to open my first text file using PHP and my PC almost freezed... please don't ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 12-29-2003
Cesar Aracena
 
Posts: n/a
Default fopen

Hello,

I am trying to open my first text file using PHP and my PC almost freezed...
please don't laught. Here's my script:

function welcometext()
{
$fp = fopen("../files/welcome.txt", "a+");

while (!feof($fp, 100))
{
$text = fgets($fp, 100);
echo $text;
}

fclose($fp);
}

What can be wrong? Thanks in advanced,

Cesar Aracena
Reply With Quote
  #2 (permalink)  
Old 12-29-2003
Cesar Aracena
 
Posts: n/a
Default Re: [PHP] fopen

Now it gives me the following error message:

Warning: fopen(websitename/esp/files/welcome.txt): failed to open stream: No
such file or directory in d:\wwwroot\websitename\esp\lib\functions.php on
line 6

But the file exists and so does the folder it is into. What can be wrong? I
also uploaded the file to my Unix web server for testing purposes, CHMOD the
folder to 777 and linked to the file but then other error appeared. When I
tried with "rb" for fopen it gave me the same error saying that the file was
missing... ???

Thanks,

"Gerard Samuel" <php-general@trini0.org> escribió en el mensaje
news:200312290120.14608.php-general@trini0.org...
> On Sunday 28 December 2003 11:17 pm, Cesar Aracena wrote:
> > $fp = fopen("../files/welcome.txt", "a+");
> >

>
> Change to
> $fp = fopen("../files/welcome.txt", "r");
>
> Use "r" to read, when you use "a" it appends (or adds) to the file
> Its also suggested to use the "b" option to so it would look like
> $fp = fopen("../files/welcome.txt", "rb");
>
> That is done for portability between *nix and windows.
>
> More info is at the manual
> http://us2.php.net/manual/en/function.fopen.php

Reply With Quote
  #3 (permalink)  
Old 12-29-2003
Gerard Samuel
 
Posts: n/a
Default Re: [PHP] fopen

On Monday 29 December 2003 09:50 am, Cesar Aracena wrote:
> Now it gives me the following error message:
>
> Warning: fopen(websitename/esp/files/welcome.txt): failed to open stream:
> No such file or directory in d:\wwwroot\websitename\esp\lib\functions.php
> on line 6
>
> But the file exists and so does the folder it is into. What can be wrong? I
> also uploaded the file to my Unix web server for testing purposes, CHMOD
> the folder to 777 and linked to the file but then other error appeared.
> When I tried with "rb" for fopen it gave me the same error saying that the
> file was missing... ???
>
> Thanks,
>


I cant say why you may be experiencing this error.
The only thing wrong with your original code was you were trying to read a
file, with fopen in append mode which is wrong.
Maybe start with reading files that live in the same directory as the calling
script, and work your way out from there...


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:31 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0