473,395 Members | 1,681 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.

Try to write files using php5 on Linux

Help!

I am using SuSE 9.3, php5 and Apache2 on Linux. I try to write files to
the hard drive using the following command:

$filename = "test.txt";
if (!file_exists($filename))
touch($filename);
if (is_writable($filename))
$myfile = fopen( $filename,'w+');
else
{
echo "Cannot write to file ($filename)";
exit(1);
}

The script neither creates a file nor open it for writing. When using
the same script on Windows everything works fine so I think it is a
permission problem.

Thanks in advance,

Matthias
Jul 22 '05 #1
22 2437
Matthias Braun wrote:
check the owner:group permission on the folder/file
if (!($fp = fopen(TEMPLATE_PATH.$path.'/'.$file, 'w')))
{
echo "ERROR open file";
} else {
fwrite($fp, $content);
fclose($fp);
}

Bye

R
Jul 22 '05 #2


Matthias Braun wrote:
Help!

I am using SuSE 9.3, php5 and Apache2 on Linux. I try to write files to
the hard drive using the following command:

$filename = "test.txt";
if (!file_exists($filename))
touch($filename);
if (is_writable($filename))
$myfile = fopen( $filename,'w+');
else
{
echo "Cannot write to file ($filename)";
exit(1);
}

The script neither creates a file nor open it for writing. When using
the same script on Windows everything works fine so I think it is a
permission problem.


Remember on Linux, the Apache web server runs as a process with very
little priveleges. If you need it to write to a file, the directory
which the file will be in needs to be writeable by everyone.

Ken

Jul 22 '05 #3
Matthias Braun wrote:
Help!

I am using SuSE 9.3, php5 and Apache2 on Linux. I try to write files to
the hard drive using the following command:

$filename = "test.txt";
if (!file_exists($filename))
touch($filename);
if (is_writable($filename))
$myfile = fopen( $filename,'w+');
else
{
echo "Cannot write to file ($filename)";
exit(1);
}

The script neither creates a file nor open it for writing. When using
the same script on Windows everything works fine so I think it is a
permission problem.

Thanks in advance,

Matthias


What are your permissions for the directory? Does the Apache user have write
permission for it?
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 22 '05 #4
SOR
<comp.lang.php , Matthias Braun , ma*******@web.de>
<42***********************@newsread4.arcor-online.net>
<Fri, 22 Jul 2005 17:30:41 +0200>
I am using SuSE 9.3, php5 and Apache2 on Linux. I try to write files to
the hard drive using the following command:

$filename = "test.txt";
if (!file_exists($filename))
touch($filename);
if (is_writable($filename))
$myfile = fopen( $filename,'w+');
else
{
echo "Cannot write to file ($filename)";
exit(1);
}

The script neither creates a file nor open it for writing. When using
the same script on Windows everything works fine so I think it is a
permission problem.


touch($filename); chmod($filename, 0766);

TMK once you create a file you need to chmod it before you can write to
it and what the folder (if any) is chmodded to is also important for non
windows hosting .
Jul 22 '05 #5
SOR
<comp.lang.php , SOR , we*******@sparesorrepair.co.uk.INVALID>
<MP************************@no-cancel.newsreader.com>
<Fri, 22 Jul 2005 18:17:10 +0100>
chmod($filename, 0766);


With regard to the webpage('filename.php') thingy .

Why isnt chmod(,) called something like change(,) if the name assigned
to the function isnt important .

Or do some things only count or have any value when it suits you ? .
Jul 22 '05 #6


SOR wrote (in part):
Why isnt chmod(,) called something like change(,) if the name assigned
to the function isnt important .

Or do some things only count or have any value when it suits you ? .


chmod is a UNIX/Linux command. AFAIK, PHP was first developed on a
UNIX/Linux platform, so you would expect some of the familiar commands
to be named the same.

Ken

Jul 22 '05 #7
SOR
<comp.lang.php , Ken Robinson , ke******@rbnsn.com>
<11**********************@g43g2000cwa.googlegroups .com>
<22 Jul 2005 10:59:25 -0700>
Why isnt chmod(,) called something like change(,) if the name assigned
to the function isnt important .

Or do some things only count or have any value when it suits you ? .


chmod is a UNIX/Linux command. AFAIK, PHP was first developed on a
UNIX/Linux platform, so you would expect some of the familiar commands
to be named the same.


What a croc of shit .

PHP has been getting developed for how many years ? .

Is putting or adding in something like webpage() beneath them or summit
and isnt part of php supposed to be about the ease of use .

What do you think the chances are that a newbie will type in headers if
they want to find out how to goto a new webpage .
Jul 22 '05 #8
I noticed that Message-ID:
<MP************************@no-cancel.newsreader.com> from SOR contained
the following:

What do you think the chances are that a newbie will type in headers if
they want to find out how to goto a new webpage .


It's a difficult one. People who are used to pointy clicky environments
(I'm not just talking about you - I see this with many of my students)
have got used to a lot of hand holding. PHP on the other hand is a bit
geeky and developed by and for people who want full control of how
things work. I'm sure you'd be even more frustrated by ASP.NET

But they can take things too far. For instance, look up 'delete' in the
manual.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 22 '05 #9
SOR wrote:
<comp.lang.php , Ken Robinson , ke******@rbnsn.com>
<11**********************@g43g2000cwa.googlegroups .com>
<22 Jul 2005 10:59:25 -0700>
Why isnt chmod(,) called something like change(,) if the name assigned
to the function isnt important .

Or do some things only count or have any value when it suits you ? .


chmod is a UNIX/Linux command. AFAIK, PHP was first developed on a
UNIX/Linux platform, so you would expect some of the familiar commands
to be named the same.

What a croc of shit .

PHP has been getting developed for how many years ? .

Is putting or adding in something like webpage() beneath them or summit
and isnt part of php supposed to be about the ease of use .

What do you think the chances are that a newbie will type in headers if
they want to find out how to goto a new webpage .


I started learning PHP a couple of years ago. It was somewhere around my 18th
or 20th language - I've been programming for close to 40 years, and have
forgotten more languages than I remember.

Even without a Unix background I found PHP quite easy to learn. Like any
language you need to learn the operators, built-in function names and the like.
But it's close enough to C, C++ and Java that I had no real trouble at all.

And yes, I found header() quite easily in the documentation. But I guess that's
because I was already familiar with HTML headers.

As for why chmod() isn't called change() - if you just used change(), what would
you be changing?

Spend a few hours, learn the functions - just like any other language.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 23 '05 #10


SOR wrote (in part):
What a croc of shit .

PHP has been getting developed for how many years ? .
PHP just celebrated it's 10th anniversary.

Is putting or adding in something like webpage() beneath them or summit
and isnt part of php supposed to be about the ease of use .
I don't think ease of use was part of the design.

What do you think the chances are that a newbie will type in headers if
they want to find out how to goto a new webpage .


It really depends on how you learn new programming languages and what
experience you've had with other languages. I seem to have an ability
to pick up new languages fairly quickly. I learned enough C in 4 days
to have my solutions to the problems given out in the 5 day class used
by the instructor and examples of very good programming. Before C I had
learned PL/1, COBOL, Fortran, Basic, and SPASM (a superset of IBM/360
Assembler).

PHP was easy for me to pick up and start using, but I am still learning
from other people in these forums. I starting learning PHP in 1999.

How did I learn. I bought books, looked at the examples, asked a lot of
questions and read the online manual. If you haven't looked at
www.php.net, you really should. There's a wealth of information and
examples in the manual.

Finally, if you don't like PHP, don't use it. There are plenty of other
web languages out there, some serverside (PERL, Python) and some
clientside (Javascript). If you want to use PHP, get used to it's
problems and pitfalls and enjoy the control it gives you in the
development of web sites.

Ken

Jul 23 '05 #11
I noticed that Message-ID: <T9********************@comcast.com> from
Jerry Stuckle contained the following:
As for why chmod() isn't called change() - if you just used change(), what would
you be changing?


change_permissions() would make sense

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 23 '05 #12
Geoff Berrow wrote:
I noticed that Message-ID: <T9********************@comcast.com> from
Jerry Stuckle contained the following:

As for why chmod() isn't called change() - if you just used change(), what would
you be changing?

change_permissions() would make sense


Too long, for one thing. Look at the original Unix commands - all very short.
Remember, Unix was first created in the days of the 110 baud teletypes. A 300
baud modem was a luxury. 1200 baud modems cost thousands.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 23 '05 #13
I noticed that Message-ID: <4o********************@comcast.com> from
Jerry Stuckle contained the following:
change_permissions() would make sense


Too long, for one thing. Look at the original Unix commands - all very short.
Remember, Unix was first created in the days of the 110 baud teletypes. A 300
baud modem was a luxury. 1200 baud modems cost thousands.


That was then. Besides it could be an alias.

I could never understand why colour could not be an alias for color in
HTML and CSS. Especially since HTML is a Brit idea <g>

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 23 '05 #14
Geoff Berrow wrote:
I could never understand why colour could not be an alias for color in
HTML and CSS.
hows about ye olde 'hue', just for pernicketyness, or are we
getting into a gray^H^Hey area??
Especially since HTML is a Brit idea <g>


GO ON MY SON!!

--
Jock
Jul 23 '05 #15
Geoff Berrow wrote:
I noticed that Message-ID: <4o********************@comcast.com> from
Jerry Stuckle contained the following:

change_permissions() would make sense


Too long, for one thing. Look at the original Unix commands - all very short.
Remember, Unix was first created in the days of the 110 baud teletypes. A 300
baud modem was a luxury. 1200 baud modems cost thousands.

That was then. Besides it could be an alias.

I could never understand why colour could not be an alias for color in
HTML and CSS. Especially since HTML is a Brit idea <g>


Yep, that was then. But if you change it, millions of scripts will change.

You want to make it an alias on your system, great. But then your scripts won't
work on other people's systems.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '05 #16
I noticed that Message-ID: <pP********************@comcast.com> from
Jerry Stuckle contained the following:
I could never understand why colour could not be an alias for color in
HTML and CSS. Especially since HTML is a Brit idea <g>


Yep, that was then. But if you change it, millions of scripts will change.


Huh? The word is interpreted by the browser. All I'd like is for
browsers to recognise that the USA does not actually own the Internet.
In fact it would be even better if browsers could respond to whatever
the native language.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 24 '05 #17
Geoff Berrow wrote:
I noticed that Message-ID: <pP********************@comcast.com> from
Jerry Stuckle contained the following:

I could never understand why colour could not be an alias for color in
HTML and CSS. Especially since HTML is a Brit idea <g>

Yep, that was then. But if you change it, millions of scripts will change.

Huh? The word is interpreted by the browser. All I'd like is for
browsers to recognise that the USA does not actually own the Internet.
In fact it would be even better if browsers could respond to whatever
the native language.


First of all, I was taling about chmod() - not color/colour.

But as to your other point - you seem to have a chip on your shoulder. What's
the difference between color and colour? Who really cares?

Yes, I'm in the U.S. But if they had spelled it colour, I'd use it. No problem.

But in the meantime you're asking all the browser manufacturers to change their
code. You're asking anyone who ever created a script to parse HTML to change
their code. You're asking the manufacturers of HTML editors to change their code.

All because of a "u"? There are far more important things in this world than
whether it's spelled color or colour!
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 24 '05 #18
I noticed that Message-ID: <xu********************@comcast.com> from
Jerry Stuckle contained the following:
Geoff Berrow wrote:
I noticed that Message-ID: <pP********************@comcast.com> from
Jerry Stuckle contained the following:

I could never understand why colour could not be an alias for color in
HTML and CSS. Especially since HTML is a Brit idea <g>

Yep, that was then. But if you change it, millions of scripts will change.

Huh? The word is interpreted by the browser. All I'd like is for
browsers to recognise that the USA does not actually own the Internet.
In fact it would be even better if browsers could respond to whatever
the native language.


First of all, I was taling about chmod() - not color/colour.


Well yes, take your point that one could write one's own aliases in
PHP.
But as to your other point - you seem to have a chip on your shoulder.
Just doing my part to prevent the USA's assimilation of the 'net <g>. I
wouldn't call it a chip, but I do think it's a serious point.
What's
the difference between color and colour? Who really cares?

Yes, I'm in the U.S. But if they had spelled it colour, I'd use it. No problem.
Someone, somewhere, decided to spell it like that. Someone who didn't
know or perhaps more importantly, didn't care that other people spelled
it differently. Sure it's a small point Jerry, but a significant one.
But in the meantime you're asking all the browser manufacturers to change their
code. You're asking anyone who ever created a script to parse HTML to change
their code. You're asking the manufacturers of HTML editors to change their code.
No I'm not. I'm saying that with a little more thought and
consideration the browsers could have responded equally well to either
spelling. I'm saying that with a little more thought the markup could
have been in any language.
All because of a "u"? There are far more important things in this world than
whether it's spelled color or colour!


I think you are focussing on the example and not seeing the bigger
picture.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 24 '05 #19
SOR
<comp.lang.php , Jerry Stuckle , js*******@attglobal.net>
<xu********************@comcast.com>
<Sun, 24 Jul 2005 09:57:37 -0500>
But as to your other point - you seem to have a chip on your shoulder.


Hes english - he has a excuse .
Jul 24 '05 #20
I noticed that Message-ID:
<MP************************@no-cancel.newsreader.com> from SOR contained
the following:
But as to your other point - you seem to have a chip on your shoulder.


Hes english - he has a excuse .


and SOR's a well balanced Scot - he has a chip on both shoulders.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 24 '05 #21
SOR
<comp.lang.php , Geoff Berrow , bl******@ckdog.co.uk>
<6b********************************@4ax.com>
<Sun, 24 Jul 2005 20:52:53 +0100>
But as to your other point - you seem to have a chip on your shoulder.


Hes english - he has a excuse .


and SOR's a well balanced Scot - he has a chip on both shoulders.


LOL :-)
Jul 24 '05 #22
Geoff Berrow wrote:
I could never understand why colour could not be an alias for color in
HTML and CSS. Especially since HTML is a Brit idea <g>


Must be only one way to do something.

# and // together is bad.
if(){} and IF ENDIF together is bad.
echo and print together is bad.
and so on.
Jul 27 '05 #23

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

Similar topics

5
by: LRW | last post by:
I've been using PHP for a few years now, have used ASP in the past, and PHP (IMO) is far superior! However, last year I had the opportunity to do some work in ASP.Net...and wow! Really liking what...
2
by: Mike | last post by:
I am sure that I am making a simple boneheaded mistake and I would appreciate your help in spotting in. I have just installed apache_2.0.53-win32-x86-no_ssl.exe php-5.0.3-Win32.zip...
0
by: _andrea.l | last post by:
I'd like to use php5 but at my work we use PHP4. How can use both togheter? I work whith Linux Fedora 4 then I have PHP5 installed so how can install PHP4 and use PHP5 for my experiment and PHP4...
0
by: Rithish | last post by:
OS : RHEL3 PHP version : 5.0.2 JDK version : 1.5.0.06 I have been trying to compile PHP with JAVA support for the past week, and all I have left to do is take a noose and hang myself. Of all...
1
by: R | last post by:
Hi All, I'm using UTF-8 encoding for my PHP scripts, output is also UTF-8. all files have UTF-8 BOM: 0xEF 0xBB 0xBF at the beginning I have PHP Version 5.1.2 on WinNT and PHP 5.1.1 on Gentoo...
4
by: Chuck Anderson | last post by:
My Web Host (Linux - Apache) recently upgraded to Php5. One thing lost in the upgrade was a global configuration that allowed me to place php.ini files in any directory and they would be read and...
1
by: Kesavan | last post by:
I install apache2 in /usr/local/apache2 and install php5 by ./configure --with-apxs2=/usr/local/apache2/bin/ apxs PHP is successfully installed in my system. But now my .php files inside...
3
by: cheesecaker | last post by:
For some reason, when PHP starts, it doesn't want to load some extensions that I KNOW are there. Here's the startup log: Parent: Received restart signal -- Restarting the server. Child 5176:...
20
by: cscorley | last post by:
For some reason, I cannot use fopen() on the file in write mode. The file "time" is in the same directory as the .php file, with permissions set to 0766. PHP Version 5.2.5 Apache/2.2.8 code...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.