Do you get any errors besides the fact that the index.php file is not created?
JRSofty
Junior Poster in Training
69 posts since Dec 2007
Reputation Points: 16
Solved Threads: 10
What is the value of $semname?
Is it a complete path or just a relative one?
JRSofty
Junior Poster in Training
69 posts since Dec 2007
Reputation Points: 16
Solved Threads: 10
Hi everyone,
I'm now fiddling over a week to fix a problem on my linux-webserver.
I have the following code:
...
$bool=mkdir(trim($semname), 0777, TRUE);
//chmod(trim($semname),0777);
$f2=fopen(trim($semname)."/index.php","w");
...
it works perfectly when working on my home server under windows but as soon as loaded up on my linux-webserver it just creates a folder with permission 755. The permission of the root-folder is also set to 0777, but no index-file is created.
What's wrong? I can't even find anything on php.net.
Thanks very much indeed
Simon
Take a look at the umask() function.
In order to create a folder with 0777 permissions you need to first set the umask to 0000, then do the mkdir(), then you can set it back to its original value.
eg:
$orig = umask(0000);
$bool=mkdir(trim($semname), 0777, TRUE);
//chmod(trim($semname),0777);
$f2=fopen(trim($semname)."/index.php","w");
umask($orig);
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
@JRSofty:
$semname is the name of the folder I want to create. Typical values are "basic0708", "public" or "member". Shouldn't be a problem for the local file system. I mean, the folder is created, just the file cannot be written to it.
@digital-ether:
thanks for that idea. It does work. The properties are set correctly. Just the file is still not created.
Maybe I need a delay between the creation of the folder and the file? I'll try that out.
[EDIT]
I tried to write to that folder when not having created it just before. No chance. Accessing all other folders work perfectly, there are just problems with ones, that I created in PHP.
[/EDIT]
Thats odd, are you sure you don't have error reporting turned off?
Is your PHP running as CGI or Apache module? What's the PHP user?
Can php create files in other directories not created via php's mkdir()?
digital-ether
Nearly a Posting Virtuoso
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
Try to add this at the beginning of your code
ini_set("error_reporting","E_ALL");
Then run your code and see if there are any errors that display.
JRSofty
Junior Poster in Training
69 posts since Dec 2007
Reputation Points: 16
Solved Threads: 10
[S]Well the warning for mkdir could be a problem. What version of PHP are you running? Can you give me a link to a phpinfo(); function?[/S]
Never mind the above you must be using PHP 4. The recursive parameter came in version 5.
As for the writing of files it is most likely because your host has PHP set in Safe Mode. Sadly this can only be changed in the php.ini and not with an ini_set(); function.
Here's a list of restrictions caused by safe mode that might help you
http://www.php.net/manual/en/features.safe-mode.functions.php
Now I'm not sure how you can change the ownership of the newly created directory but according to that list the fopen function will still work if the uid is the same for the directory and the currently running script.
JRSofty
Junior Poster in Training
69 posts since Dec 2007
Reputation Points: 16
Solved Threads: 10