Creating directories and files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MT
Forum Newbie
Posts: 3
Joined: Mon Jul 28, 2003 12:13 am
Location: Volgograd, Russia

Creating directories and files

Post by MT »

I`m trying to create a file:

Code: Select all

<?php
$fp=fopen("somefile.php4","w"); 
?>
or a directory:

Code: Select all

<?php
mkdir("somedir",0755); 
?>
Server (Apache, Linux) responds:
"Warning: fopen(somefile.php4): failed to open stream: Permission denied ..."
or
"Warning: mkdir(somedir): Permission denied ..."
respectively.
Please explain what`s wrong.

On my home computer (Windows 98, Microsoft Personal Web Server) it works fine.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post by kettle_drum »

The permissions for writting to the folders that your attempting to do will be not aloud. CHMOD the dir so that you can write to it.
Black Unicorn
Forum Commoner
Posts: 48
Joined: Mon Jun 16, 2003 9:19 am
Location: United Kingdom

Re: Creating dirs & stuff

Post by Black Unicorn »

If PHP is running as an Apache module, I found that you have to change the directory ownership as well.

In my case it didn't work until I chown'ed the directory to httpd. But once I did that, I couldn't ftp using anything but httpd as a username ...

I hope this advice doesn't cause more problems than solutions.

Regards,
H
MT
Forum Newbie
Posts: 3
Joined: Mon Jul 28, 2003 12:13 am
Location: Volgograd, Russia

Creatinf directories and files

Post by MT »

Thanks for replies.
I`ve understood what the problem was: your FTP-client and your PHP-scripts have different UIDs, i.e. they are two different owners. They can`t freely manipulate each other`s folders and files, unless they have permissions set to 0777. And even then, it seems, they can`t delete each other`s files and folders.

So my solution was as follows.
I first made a directory with my FTP-client inside the directory where scripts reside and set its permissions to 0777.
Then altered the script to make it create files and directories in that directory.
Of course, I had to make respective changes all over my site, because of the additional directory.
Now it all works fine. :D
Post Reply