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

Do you get any errors besides the fact that the index.php file is not created?

Unfortunately not.
I also echoed the variable $f2, which is supposed to be something like "Ressource id #2", but I just get an empty string.

Here is a dump:

is_writebale: 
Ressource:

Any idea?

What is the value of $semname?

Is it a complete path or just a relative one?

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);

@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]

@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()?

> Thats odd, are you sure you don't have error reporting turned off?

I don't know. The script is running on a server and I don't have access to the php.ini


Is your PHP running as CGI or Apache module? What's the PHP user?

it is running under apache. The user is, as far as I know, wwwrun.

Can php create files in other directories not created via php's mkdir()?

Yes. I tried it out. It works perfectly.

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.

I had an intense look at my server-settings, and realized, that I can turn the error-reporting on.

These are the messages I get:

Warning: mkdir() expects at most 2 parameters, 3 given in /home/www/web573/html/web/anglistik/dat/code/redaktion.php on line 141

Warning: fopen() [function.fopen]: SAFE MODE Restriction in effect. The script whose uid is 1922 is not allowed to access /home/www/web573/html/web/anglistik/test owned by uid 33 in /home/www/web573/html/web/anglistik/dat/code/redaktion.php on line 146

Warning: fopen(./test/index.php) [function.fopen]: failed to open stream: No such file or directory in /home/www/web573/html/web/anglistik/dat/code/redaktion.php on line 146

Maybe you need some explainations:
1) I create a dir called './test'
2) I want to create an index.php-file in it './test/index.php'
3) Writing data in it (I left these messages out)

seems as if SAFE MODE restricts the access to my dir. But why? And is there any work-around?

Perhaps, I could write an 404-errorpage that redirects the browser to the file I want to?

[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.

well nevermind, but thanks anyway to everyone - it helped a lot. I have to solve it then with a redirection. Did that already some years ago but I thought it is nicer to do it this way.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.