473,387 Members | 1,548 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,387 software developers and data experts.

SAFE MODE,fopen, and chmod

Hi all,
Consider this case:
I have a free php hosting account (a LAMP host) with an account name
(also the name of my directory) 'sample'.
Under 'sample', I have php scripts which can create files and folders
programmatically. I have manually created a directory called 'users'
under 'sample' and have given it a chmod 777 successfully.
From my script in 'sample', say myscript.php, I can successfully create

any number of files inside sample/users/, say, sample/users/aaaaa.txt,
sample/users/bbbbb.css, etc. I can also create directories at runtime,
say, sample/users/mydir1, sample/users/mydir2 etc. and can also
successfully chmod each to 777 (all this from myscript.php).
The host is "running in SAFE MODE", where, it seems that for fopen,
mkdir and many other functions, a check is done for the UID of the
script-running process to be the same as the UID of each resource
concerned(mydir1, mydir2, aaaaa.txt etc) and only if the UIDs match, is
the function allowed to work successfully.

The problem is that while I can make all these directories(mydir1,
mydir2, etc) under sample/users and files aaaaa.txt and bbbbb.css under
sample/users, I cannot make files inside mydir1, mydir2 etc. _inspite_
of the fact that I can _successfully_(confirmed from independent
filemanager utility) chmod all these created directories to 777.

The message I get is something like: Warning fopen(): SAFE MODE
restriction, the script whose UID is 12878 is not allowed to access
sample/users/mydir3 owned by UID 99 in /path/to/script/myscript.php on
line 484.

This inspite of the fact that the newly created sample/users/mydir3 has
been successfully chmodded to 777 as is visible from the host's
filemanager utility!

The same script has in the prior lines created the directory
sample/users/mydir3 and many files like sample/users/ccccc.css,
sample/users/dddddd.css and so on, without a problem. Plus, not having
permissions on mydir3 is ruled out because the script just made it
itself and chmodded it to 777.

Any clues?

Thanks in advance,
Joseph S.

Nov 4 '05 #1
2 6175
Joseph S. wrote:
I have a free php hosting account
hmmmm.

The message I get is something like: Warning fopen(): SAFE MODE
restriction, the script whose UID is 12878 is not allowed to access
sample/users/mydir3 owned by UID 99 in /path/to/script/myscript.php on
line 484.

This inspite of the fact that the newly created sample/users/mydir3 has
been successfully chmodded to 777 as is visible from the host's
filemanager utility!


what are the permissions now, and what uid/gid owns the file when viewed
from outside PHP?

C.
Nov 4 '05 #2
That's the way safe-mode works.

The files going into the users/ folder are created by the "apache"
(webserver) user.

The script running is owned by your account (eg "sample").

Since the UID's aren't the same you can't do anything.

See http://www.php.net/features.safe-mode

You could ask the host if they can enable safe_mode_gid and make sure
that your user and the apache user are in the same group but that's
about all you can do apart from disabling safe-mode.

(there are no workarounds, that's just the way it works).

Joseph S. wrote:
Hi all,
Consider this case:
I have a free php hosting account (a LAMP host) with an account name
(also the name of my directory) 'sample'.
Under 'sample', I have php scripts which can create files and folders
programmatically. I have manually created a directory called 'users'
under 'sample' and have given it a chmod 777 successfully.
From my script in 'sample', say myscript.php, I can successfully create

any number of files inside sample/users/, say, sample/users/aaaaa.txt,
sample/users/bbbbb.css, etc. I can also create directories at runtime,
say, sample/users/mydir1, sample/users/mydir2 etc. and can also
successfully chmod each to 777 (all this from myscript.php).
The host is "running in SAFE MODE", where, it seems that for fopen,
mkdir and many other functions, a check is done for the UID of the
script-running process to be the same as the UID of each resource
concerned(mydir1, mydir2, aaaaa.txt etc) and only if the UIDs match, is
the function allowed to work successfully.

The problem is that while I can make all these directories(mydir1,
mydir2, etc) under sample/users and files aaaaa.txt and bbbbb.css under
sample/users, I cannot make files inside mydir1, mydir2 etc. _inspite_
of the fact that I can _successfully_(confirmed from independent
filemanager utility) chmod all these created directories to 777.

The message I get is something like: Warning fopen(): SAFE MODE
restriction, the script whose UID is 12878 is not allowed to access
sample/users/mydir3 owned by UID 99 in /path/to/script/myscript.php on
line 484.

This inspite of the fact that the newly created sample/users/mydir3 has
been successfully chmodded to 777 as is visible from the host's
filemanager utility!

The same script has in the prior lines created the directory
sample/users/mydir3 and many files like sample/users/ccccc.css,
sample/users/dddddd.css and so on, without a problem. Plus, not having
permissions on mydir3 is ruled out because the script just made it
itself and chmodded it to 777.

Any clues?

Thanks in advance,
Joseph S.

Jan 30 '06 #3

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

Similar topics

1
by: while_1 | last post by:
I have a program (site_bot, found at phpclasses.org) that 1) recursively reads a file system starting at locationA, and stores lots of filesystem info in a mysql schema on the fly. 2)...
3
by: Jeremy Shovan | last post by:
What do I need to change to use the opendir() function when safe mode is in affect?? I have root access to the server and can make any changes neccessary except turn safe mode off Thanks in...
0
by: Pjotr Wedersteers | last post by:
(Suse 9.0, Apache 2.048, PHP 4.3.3 - all default install from SuSe ISO) I have in my wwwroot folder (/srv/www/htdocs) a folder called counters. I have embedded a page counter script into several...
9
by: bird | last post by:
What can cause the PHP code fopen("filename","a") to fail with permission denied message as below? ------------------ Warning: fopen(filename): failed to open stream: Permission denied in...
4
by: pdav | last post by:
Hi! Is there any solution to create a directory with one script with mkdir(), and then write a file (or move an uploaded file) in this directory with another script? The problem is, that the...
0
by: Chris | last post by:
I used mkdir() to create a directory, then use chmod() to change the mode to 0777 in one script. When I try to create a file using touch() in another script, I get the SAFE MODE error about the...
3
by: Rik | last post by:
Hello, first of all, my provider sucks, newsserver is down for the #nth time now, offcourse when I have an urgent question.... So this will be me first time using Google Groups, forgive me if...
3
by: IamtheEvster | last post by:
Hi there, I'm using fopen for the first time and I know I'm running into a permissions problem, but I can't seem to resolve it and any help would be greatly appreciated. I'm running PHP5 and...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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:
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
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.