Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Create directories on the fly...



4:24 pm on Jan 20, 2005 (gmt 0)

10+ Year Member


Just curious to know is it possible to create directories on the fly?

What I have done is created a script when you can add categories and subcategories, but what I would like to do is create a directory physcially within that category. For instance using the mkdir command using linux. In a way traversing through and creating a directory.

An example would be:

If I created a category called business and econony then it would display this in the address bar.


Then perhaps under Business and Economy, a category called Accounting, then it would display the following:


Hopefully I'm making some sense here.

Heres the code:

function maketree($rootcatid,$level)
$sql="select catid,cat_name
from quiz_category
where parentid=$rootcatid
order by cat_name";


while (list($DBcatid,$DBcatname)=mysql_fetch_row($result))
$display="<img src=http://www.domain.com/spacer.gif border=0 width=$width height=12>";
if ($DBcatid==1)
$display.="<input type=\"radio\" name=\"quest_type\" value=$DBcatid checked>";
$display.="<input type=\"radio\" name=\"quest_type\" value=$DBcatid>";
echo $display;

if ($submit=='Add New Category')
if ($new_cat!='')
mysql_query("insert into quiz_category
(parentid,cat_name) values ($quest_type,'$new_cat')");

# need to create directory here

echo "<br><br><center><b>New category entered</b></center>";
echo "<br><br><center><b>New category name must be entered</b></center>";

Many Thanks

W :o)


6:07 pm on Jan 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I might not have quite got you right, since this sounds like such an obvious response, but there is a php function

This might be what you're looking for. In the user-contributed notes you can find functions for creating multiple directories.


9:23 am on Jan 21, 2005 (gmt 0)

10+ Year Member

Thanks for the response,

Yeah I did look into that, obviously there are other file functions I need to look into.

The problem lies where I need to check if the directory exist for the top level category and then the subcategories beneath, and then create a directory if it does not exist.



10:04 am on Jan 21, 2005 (gmt 0)

10+ Year Member

You could try using the Linux mkdir command with the --parent option. That will create all parent directories if they do not already exist.




10:21 am on Jan 21, 2005 (gmt 0)

10+ Year Member

could you use apache rewrite to achieve the same result? in other words create 'virtual' directories and access any data from a database using parts of the directory path as a key.


10:41 am on Jan 21, 2005 (gmt 0)

10+ Year Member

Thanks Guys for the response.

Some interesting points there, I was actually thinking of the mod_rewrite function, but it ain't my strong point, hence this is my workaround but I'll post the code when I done it, and see what you all think.



Featured Threads

Hot Threads This Week

Hot Threads This Month