473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

N00b question: creating files

Hi,

I am rather new to PHP and a relative newbie to Linux too.
I have a webserver at home (Apache 2.0.48 on SuSe 9.0, PHP4).
I have some scripts, one of them needs to be able to create logfiles
somewhere on my machine. It must also later be able to read from and write
to these files again.

Sofar I get a permission error. I tried chmodding 666 or 777 the directory
in which the files could reside, to no avail.
How do I set up the permissions so that my script can simply fopen a file
for writing. Or if that's not the issue, what am I doing wrong or
overlooking ?

The errors:
Warning: fopen(logfiles\log1.txt): failed to open stream: Permission denied
in script1.php on line 142
Warning: fwrite(): supplied argument is not a valid stream resource in
script1.php on line 154
Warning: fclose(): supplied argument is not a valid stream resource in
script1.php on line 161
It's the first I am puzzled about, the 2nd and 3rd are a logical
consequence.

By the way, reading from and writing to a file I have previously created
myself with exactly the names I tried to get created by the script (echoed
the name, ok) is no problem at all.
So I don't think it has much to do with a safemode or open_basedir setting.
I also tried creating the scripts in the same dir the script itself resides.
Did not work either.

I think I listed all the relevant info here. Who can help me ?

TIA
Pjotr
Jul 17 '05 #1
3 1735


On 4-Jul-2004, "Pjotr Wedersteers" <x3****@westerterp.com> wrote:
Warning: fopen(logfiles\log1.txt): failed to open stream: Permission
denied
in script1.php on line 142


try fopen('logfiles/log1.txt','w');

backslash is an escape. Assuming the your filename was in quotes it would be
interpreted as logfileslog1.txt, probably not what you want.

fopen also requires the mode as the second parameter. 'w' for write, 'a' for
append, etc

http://www.php.net/manual/en/function.fopen.php
--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2

"Tom Thackrey" <us***********@nospam.com> wrote in message
news:YB*******************@newssvr29.news.prodigy. com...


On 4-Jul-2004, "Pjotr Wedersteers" <x3****@westerterp.com> wrote:
Warning: fopen(logfiles\log1.txt): failed to open stream: Permission
denied
in script1.php on line 142
try fopen('logfiles/log1.txt','w');

backslash is an escape. Assuming the your filename was in quotes it would

be interpreted as logfileslog1.txt, probably not what you want.

fopen also requires the mode as the second parameter. 'w' for write, 'a' for append, etc

http://www.php.net/manual/en/function.fopen.php


Your web server user needs write access to the folder you're trying to
create in, too. Check at the console. And post source that doesn't work so
we can see if there are obvious problems.

HTH
Garp
Jul 17 '05 #3

"Garp" <ga***@no7.blueyonder.co.uk> wrote in message
news:fN*********************@news-text.cableinet.net...

"Tom Thackrey" <us***********@nospam.com> wrote in message
news:YB*******************@newssvr29.news.prodigy. com...


On 4-Jul-2004, "Pjotr Wedersteers" <x3****@westerterp.com> wrote:
Warning: fopen(logfiles\log1.txt): failed to open stream: Permission
denied
in script1.php on line 142
try fopen('logfiles/log1.txt','w');

backslash is an escape. Assuming the your filename was in quotes it

would be
interpreted as logfileslog1.txt, probably not what you want.

fopen also requires the mode as the second parameter. 'w' for write, 'a'

for
append, etc

http://www.php.net/manual/en/function.fopen.php


Your web server user needs write access to the folder you're trying to
create in, too. Check at the console. And post source that doesn't work so
we can see if there are obvious problems.

What a silly mistake of me to use the wrong windoze backslashes. SIGH. But
it works now, thanks for the pointers. Rights have been properly assigned
now, webuser has rw rights to the directory.

Back to the development table to further exploit that fine PHP! I like it
sofar!
Pjotr
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matt | last post by:
I'd like to overwrite just one line of a binary file, based on a position set by seek(). Is there no way to do this? As far as I can tell I need to read the whole file, change the line, and write...
12
by: Mal Ice | last post by:
I am creating an initial index.htm page on which I show some disclaimers and introduction information. In the head section I have Javascript which determines the screen resolution of the client....
3
by: Anupam Kapoor | last post by:
hi all, a python n00b, so please bear with me. i have a simple question: i generally name python sources as a-simple-python-example.py. when i try to import a module named as above, i...
4
by: turnstyle | last post by:
Hey all, sorry for asking such a grunt question, and thanks in advance for any help... My hosting ISP offers access to their MS-SQL database, and my understanding is that it's generally simplest...
15
by: Anton Gavrilov | last post by:
Hi all, I seek your advice on where to start if I want to write a compiler for a toy C-like language I invented (or, rather, am in the process of inventing). Yes, yes, I know I'm crazy and the...
1
by: newgenre | last post by:
I am using a pre-built package of code for my site, which is called EasyDisc. All it does is it creates an interactive forum on your site, like any forum you see anywhere. I am having a problem...
7
by: Alan | last post by:
When you use a function like I see posted here often, like: Public Function Whatever() stuff... End Function What do you actually do with that to make it run? I assumed you put it in a...
5
by: Omar | last post by:
I'm learning how to program python. a few questions a) I'm mostly interested in creating exe's that have to do with music -- things to help me keep track of chord progressions, transpositions,...
3
by: rtlshred | last post by:
Hello I have just, just started C++ programing. the complier I am using is Dev C++ Here is my question: Once I have written some code, How do I run the program and see the output?
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.