making new folders...
Moderator: General Moderators
making new folders...
Lets say I've got a users table in mysql... I would want each user to have their own folder, in example: http://www.mysite.com/users/[b]username[/b]/*.*, where *.* are all the files that are inside that certain folder.
Firslty make sure that 'users' is readble/writeable by the web server. (use chmod from the shell to alter this).
Than do something like this:
Andy
Than do something like this:
Code: Select all
<?php
$path = "/usr/home/foo/www/users";
$id = @mysql_connect($host,$user,$pass) or
die("Unable to connect to mysql server: $host");
@mysql_select_db($db,$id) or
die("Unable to select database: $db");
$result = @mysql_query("SELECT * FROM table",$id) or die("Unable to perform query");
while ($row = @mysql_fetch_array($result,MYSQL_ASSOC))
{
if (!(mkdir("{$path}/{$rowї'username']}",0777)))
echo "<p>Could not create directory for {$rowї'username']}</p>\n";
}
@mysql_free_result($result);
?>Well, that depends... If you have access to run system commands through PHP then you could choose a method like:phice wrote:amnuts: how would I copy all of the files in one folder, to the folder that I just created?
system("cp /foo/bar/* {$path}/{$row['username']}/");
or
$return = `cp /foo/bar/* {$path}/{$row['username']}/';
If you don't, then you'll have to do it the long way round and use opendir, go through each file and copy it individually. If you want a demo of that I can post it up.
Andy
