so far, that is impossible to me
i've looked into copy(), mkdir(), but i have yet to see a variation that enables both to work together.
i'm way to inexpirenced to script my own code up that mixes thoses two, does anyone know how or have a tutorial that shows you?
thanks.
creating a directory and automatically copy a file there
Moderator: General Moderators
THis is how I do it
Code: Select all
<?php
$folder = new_dir;//name the dir
//create the dir, and chmod to 777
mkdir($folder, 0777);
//read the dir, if no files (which there shouldn't be), then create the files
$file = readdir($folder);
if(!$file):
//moves back into the new dir
chdir($folder);
//starts the creation of the new files
$newfilename = "your_file_name.ext";
$newfile = fopen($newfilename,"w");
$content = "Whatever you want written to the new file";
fwrite($newfile,$content);
fclose($newfile);
?>not sure if I got the point, but if you want to create (possibly) a directory tree try this one (completely untested)
Code: Select all
<?php
function createDirectory($path)
{
// testings if you'd like
// $path maybe already a file/dir
mkdir($path);
}
function copyTo($src, $dest)
{
$path = split('/', $dest);
$dest = '';
$file = array_pop($path);
foreach($path as $subpath)
{
$dest .= $subpath.'/';
createDirectory($dest);
}
$dest .= $file;
return copy ($src, $dest);
}
?>$src is the path to the file you want to copy
take a look at http://www.php.net/manual/en/function.copy.php
take a look at http://www.php.net/manual/en/function.copy.php