Create folder/directory

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
jrcal
Forum Newbie
Posts: 3
Joined: Fri Jul 30, 2004 1:14 pm

Create folder/directory

Post by jrcal »

I searched the forum for this but was unable to find anything - so I hope I'll have more luck with this post.

I am just starting to program with PHP, and I was wondering if there was any PHP script or function that I could use either to create folders/directories on my Linux server, or create new html files on my server.

For example, say I wanted to create a folder named news or events - I would want to type it in through a form and click "Create" - and have it create that new folder/directory.

Thanks! :)
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

[php_man]
mkdir
Makes directory (PHP 3, PHP 4 )
bool mkdir ( string pathname [, int mode] )

Attempts to create the directory specified by pathname.

Note that you probably want to specify the mode as an octal number, which means it should have a leading zero. The mode is also modified by the current umask, which you can change using umask().

Note:
Mode is ignored on Windows, and became optional in PHP 4.2.0.

The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page.

copy to clipboard
<?php
mkdir ("/path/to/my/dir", 0700);
?>
Returns TRUE on success or FALSE on failure.

See also rmdir().
[/php_man]
User avatar
potsed
Forum Commoner
Posts: 50
Joined: Sat Oct 09, 2004 12:00 pm
Location: - South Africa

Post by potsed »

jrcal
Forum Newbie
Posts: 3
Joined: Fri Jul 30, 2004 1:14 pm

Post by jrcal »

Wonderful. These are great!

Thanks guys!
Post Reply