homepage Welcome to WebmasterWorld Guest from 107.20.109.52
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Create directories on the fly...
woldie




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

Hi,

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.

[domain.com...]

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

[domain.com...]

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

$result=mysql_query($sql);

while (list($DBcatid,$DBcatname)=mysql_fetch_row($result))
{
$width=($level+1)*24;
$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>";
}
else
{
$display.="<input type=\"radio\" name=\"quest_type\" value=$DBcatid>";
}
$display.="$DBcatname<br>\n";
echo $display;
maketree($DBcatid,$level+1);
}
}

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>";
}
else
echo "<br><br><center><b>New category name must be entered</b></center>";
}

Many Thanks

W :o)

 

mincklerstraat




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

I might not have quite got you right, since this sounds like such an obvious response, but there is a php function
mkdir() [be.php.net].

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

woldie




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

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.

woldie.

johnt




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

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

Cheers

John

incywincy




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

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.

woldie




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

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.

Woldie.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved