473,651 Members | 2,466 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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($filenam e, $mytext);
fclose($filenam e);

?>

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 2790
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**********@g mail.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**********@g mail.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**********@g mail.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($filenam e, $mytext);
: fclose($filenam e);

: ?>

: 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************ **********@g47g 2000cwa.googleg roups.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************ *********@z14g2 000cwz.googlegr oups.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
1750
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 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.
11
4745
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 fairly similar to what I need. I really think it is a simple matter if you know C programming, but to me it is not easy at all. An example from some "professional" C programmer will probably give me all I need to complete it into exactly what I need....
1
2225
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 files with identical code (noted in the code below) which i would like in my general header file. When i try this the compiler complains that the remaining code in the c files needs to access the file to but can't. Could somebody point out how...
15
21124
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 other grid. So, in the SelectionChanged event, I get the IDs of the selected rows in the first grid, and.. this is where i get stuck :)
8
7513
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 same words but in jumbled order they should match and print only the dissimilar lines.The program also checks for multiple entries of the same line. Here file 2 converts to file 3 which is in the format of file1 and i compare file1 with file3.
15
15066
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 the output file but this is tedious. Imagine typing 1000 filenames...is there a efficient way to do this?? Thanks
3
1672
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 = fileIn.Substring(0,fileIn.LastIndexOf(".")) & session("User").CompanyID & fileIn.Substring(fileIn.LastIndexOf(".")) pathFileOut = Server.MapPath("\Uploads") & "\" & fileIn.Substring(0,fileIn.LastIndexOf(".")) & "Temp" &
1
3555
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 permission denied problem. Warning: fopen(/var/www/html/dotproject/files/temp/temp1.pdf): failed to open stream: Permission denied in /var/www/html/dotproject/modules/projects/reports/tasklogs.php on line 307 Could not open file to save PDF. ...
11
1478
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 = ("hitcounter.txt"); $hits = file($count_my_page); $hits ++;
0
8275
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8795
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8460
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.