473,320 Members | 2,164 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,320 software developers and data experts.

Creating files using fopen that are unlocked!

Hi everyone

i'm trying to setup my website to create new webpages dynamically using
php but I am have a major problem in that whenever i create a file it
is always created locked so that it can only be read even when i
specify read and write access.

Here is a basic example of the code I am using (I am using a Mac OSX
10.3.9):

<?php

$filename = '/Users/myusername/sites/mysitefolder/newfile.php';
$mytext = 'my text';

fopen($filename, 'w+');
fwrite($filename, $mytext);
fclose($filename);

?>

When i run this program all it does is create a blank file with
read-only access. My question is what settings do I need to change that
will enable me to create writable files using PHP?

Sep 11 '05 #1
9 2777
I can narrow the problem down a bit more which might help. I can create
a file when I use 'w' or 'w+' even though it is read only. But if try
to create a file such as fopen($filename, 'r') or 'r+' php wont create
it.

Sep 11 '05 #2
Try changing the permissions on the file. You probably have permissions
to create files in the directory, however, the default permissions on
the file created is probably not enough for you to edit it:
http://www.php.net/manual/en/function.chmod.php

--
Bradley Holt <br**********@gmail.com>
http://www.gtalkprofile.com/profile/2.html

Sep 11 '05 #3
While opening a file with the 'r' or 'r+' option, PHP will not attempt
to create the file. PHP will only attempt to create the file with the
'w' or 'w+' option.

--
Bradley Holt <br**********@gmail.com>
http://www.gtalkprofile.com/profile/2.html

Sep 11 '05 #4
Thanks for the reply bradley. the problem is that i need these files to
be created with the file permissions in place. A funny thing is that
the owner of these files is given as "www" not my username. Do you have
any idea what that could mean?

Sep 11 '05 #5
Yes, that's a common username I've seen when creating files from
scripts. Unfortunately, you will need to modify the permissions at
least temporarily or else you won't be able to write to the file. You
may be able to get away with chowning the file to your username
instead:
http://www.php.net/manual/en/function.chown.php

--
Bradley Holt <br**********@gmail.com>
http://www.gtalkprofile.com/profile/2.html

Sep 11 '05 #6
Thanks again bradley. i tried chown but it didn't work.

Sep 11 '05 #7
monomaniac21 (ma********@msn.com) wrote:
: Hi everyone

: i'm trying to setup my website to create new webpages dynamically using
: php but I am have a major problem in that whenever i create a file it
: is always created locked so that it can only be read even when i
: specify read and write access.

: Here is a basic example of the code I am using (I am using a Mac OSX
: 10.3.9):

: <?php

: $filename = '/Users/myusername/sites/mysitefolder/newfile.php';
: $mytext = 'my text';

: fopen($filename, 'w+');
: fwrite($filename, $mytext);
: fclose($filename);

: ?>

: When i run this program all it does is create a blank file with
: read-only access. My question is what settings do I need to change that
: will enable me to create writable files using PHP?

RTFM for fopen, chmod, and umask.

"Access" controls who can do what operations on the file.

"Mode" tells the open command what your program wants to do right now (and
the "access" controls if you will be allowed to do it).

'w+' does not create a file with write _access_, it opens a file _handle_
in read/write _mode_.

It is perfectly possible to open (and thereby create) a new file using a
file handle in write _mode_, but for the file thus created to have read
only access permissions.

--

This programmer available for rent.
Sep 12 '05 #8
In article <11**********************@g47g2000cwa.googlegroups .com>,
ma********@msn.com says...
Thanks again bradley. i tried chown but it didn't work.


I'm guessing that SafeMode is enabled on your host. That precludes a
whole suite of otherwise-available functions, including chown.
Oct 6 '05 #9
In article <11*********************@z14g2000cwz.googlegroups. com>,
ma********@msn.com says...
Hi everyone

i'm trying to setup my website to create new webpages dynamically using
php but I am have a major problem in that whenever i create a file it
is always created locked so that it can only be read even when i
specify read and write access.


This is probably not quite what you are looking for, but what about an
alternative?

Based on other responses in this thread, it appears that your host has
some restrictions in place, not the least of which is PHP's SafeMode,
which severely limits (1) the whole file creation process/access
process, (2) changing permissions, and (3) running external programs.
Modifying INI settings is affected as well. Do a search for SafeMode in
the PHP manual to get all the specifics.

Meanwhile, here is my take...

Are indivudual files really the best what to do this?

PHP is not really designed to store data in files. Rather, if your host
also provides a MySQL hookup, a better route might be to store your
pages in a database table, rather than individual files. You would then
have a query look up the individual page's HTML code based on, say, a
variable called PAGE_ID, which you could pass via the URL and retrieve
with $_GET['PAGE_ID']

Not the ideal solution for every possible application, I know. Just a
thought.

- GC
Oct 6 '05 #10

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

Similar topics

3
by: Pjotr Wedersteers | last post by:
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...
11
by: MM | last post by:
Hi I have never written any C programs before, but it seems that I need to do so now. Hope some of you out there can spend a few minutes and help me by writing a simple example of something...
1
by: Lorenzo Mugnai | last post by:
Hi everyone, Below is my code which basically opens a file and appends some text if the file is below a certain size, if not it archives the file and begins a new one. The problem is i have four...
15
by: Ben | last post by:
Hey, Not sure if this is the right group to post this on, so sorry in advance if it isn't. I'm using the VS.NET 2005 beta, and am trying to fill one grid, based on what is selected in the...
8
by: Frost | last post by:
Hi All, I am a newbie i have written a c program on unix for line by line comparison for two files now could some one help on how i could do word by word comparison in case both lines have the...
15
by: leorulez | last post by:
Is there any way to read multiple files (more than 1000 files) and then write into one single output file using C? Right now in my program, I have a loop which asks for the filename and writes into...
3
by: tshad | last post by:
oThumbnail.Save is giving me an error: System.Runtime.InteropServices.ExternalException: A generic error occurred in GDI+. theFileName = New FileInfo(strFileName) fileOut =...
1
by: doctorhardik | last post by:
other interesting thing i observe during my work which i describe below: i am using dotproject2.0.4 on fc3. it is working fine. but i want to generate pdf file report during this time i face...
11
by: tony19760619 | last post by:
To make this work on a single page you will need to create/modify 4 files. So here goes... Create a file called counter.php and put following code in it: <?php //Counter $count_my_page =...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.