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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
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... |
![]() |
| Thread Tools | |
| Display Modes | |
|
|