mkdir()
Moderator: General Moderators
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
mkdir()
I keep having problems with mkdir().
I am able to make the directory.
mkdir('hi',0755);
After I make the directory, it is the same as all my other directorys exept for the fact that the user and group are different.
All the properties and numeric values are the same exept user and group name. Most them say "SkitzoBlog", but when I create a directory using mkdir, it sets user and group to 48.
So when I try to upload files to my created directory using mkdir, it says i dont have permission.
How can I fix this problem?
I am able to make the directory.
mkdir('hi',0755);
After I make the directory, it is the same as all my other directorys exept for the fact that the user and group are different.
All the properties and numeric values are the same exept user and group name. Most them say "SkitzoBlog", but when I create a directory using mkdir, it sets user and group to 48.
So when I try to upload files to my created directory using mkdir, it says i dont have permission.
How can I fix this problem?
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
some more info with my problem.
after reading, learned about chown and chgrp.
the output
after reading, learned about chown and chgrp.
Code: Select all
mkdir($TheUser1, 0755);
$uid = 733;
$gid = 733;
chown($TheUser1,$uid);
chgrp($TheUser1,$gid);
$fp = fopen($TheUser1.'/die.txt','w');
fwrite($fp,'hihihihi');
fclose($fp);Warning: chown failed: Operation not permitted in /home/virtual/site157/fst/var/www/html/registeraccount.php on line 74
Warning: chgrp failed: Operation not permitted in /home/virtual/site157/fst/var/www/html/registeraccount.php on line 75
Warning: SAFE MODE Restriction in effect. The script whose uid is 733 is not allowed to access /home/virtual/site157/fst/var/www/html/ggg owned by uid 48 in /home/virtual/site157/fst/var/www/html/registeraccount.php on line 76
Warning: fopen("ggg/die.txt", "w") - No such file or directory in /home/virtual/site157/fst/var/www/html/registeraccount.php on line 76
Warning: fwrite(): supplied argument is not a valid File-Handle resource in /home/virtual/site157/fst/var/www/html/registeraccount.php on line 77
Warning: fclose(): supplied argument is not a valid File-Handle resource in /home/virtual/site157/fst/var/www/html/registeraccount.php on line 78
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
I dont understand what that tutorial is trying to tell me to do. I just know I have to create a directory, then write some files to it. I keep getting permission denied errors.
What is so different from creating a directory threw the FTP or threw php? I cant write any files to any directorys I create threw php.
What is so different from creating a directory threw the FTP or threw php? I cant write any files to any directorys I create threw php.
A folder's permissions dictate which UID can do what. In order to create a file in a dir, the UID in question must have the write permission.Every file and folder has an owner and a group.
...
You'll notice that php runs under a different UID than the one used by your FTP program.
If php doesn't own the parent folder it can't write files unless permissions are set at, say, 777 which allows any UID to anything in the dir. Same deal for uploading with FTP.
Most FTP programs will have a dirinfo command (or something similar) which allows you to view owners, groups and permissions.
-
psychotomus
- Forum Contributor
- Posts: 487
- Joined: Fri Jul 11, 2003 1:59 am
right I understand that part about the FTP. If i view folders I create with my ftp program, it will have a owner and group. WHen I create a folder threw php then view threw the FTP program, it will not have a odd # as the owner and group.
So how am I suppose to create a folder and copy some files into it if the owners and groups are different?
So how am I suppose to create a folder and copy some files into it if the owners and groups are different?
psychotomus,
If you're having the same problems as me, i.e. you want to create directories/write files 'on-the-fly' using you PHP script (for instance someone else could upload files using their browser at a time you are not aware), then it might be possible to solve this problem by putting the following line in your .htaccess file:
AddHandler cgi-script .php
This should activate your own account's PHP install and hence upload/create/carry out file transactions using your own username and group.
However, generally speaking if you are not fiddling your script extensions using a <Files...> directive in your .htaccess, this should not be required and your PHP scripts should be run by your own account already.
If you are, then you need to use the above directive for whatever extensions you've altered through your config. If (by any chance) you've done what I did, which is take the extension off the scripts and used ForceType to change specific (extensionless) files to PHP, then I'm afraid
AddHandler cgi-script .
Does not work (perhaps this could arguably be a fault with Apache).
Let me know how it goes - I still haven't managed to come up with an acceptable solution to this problem.
Mark
Cheers
Mark
If you're having the same problems as me, i.e. you want to create directories/write files 'on-the-fly' using you PHP script (for instance someone else could upload files using their browser at a time you are not aware), then it might be possible to solve this problem by putting the following line in your .htaccess file:
AddHandler cgi-script .php
This should activate your own account's PHP install and hence upload/create/carry out file transactions using your own username and group.
However, generally speaking if you are not fiddling your script extensions using a <Files...> directive in your .htaccess, this should not be required and your PHP scripts should be run by your own account already.
If you are, then you need to use the above directive for whatever extensions you've altered through your config. If (by any chance) you've done what I did, which is take the extension off the scripts and used ForceType to change specific (extensionless) files to PHP, then I'm afraid
AddHandler cgi-script .
Does not work (perhaps this could arguably be a fault with Apache).
Let me know how it goes - I still haven't managed to come up with an acceptable solution to this problem.
Mark
Cheers
Mark