Hey Dill.
I was just trying to help you out, and wasn't 100% sure that the code would work, although I had thought it would. CHMOD is new to me, but if you need to read more on it go here.
As far as the other questions you pose....
The way the the code is written I could be wrong.
Try this:
<?php
$dir = $_REQUEST['dir_name'];
$id = $_REQUEST['id'];
$cat = $_REQUEST['cat_id'];
$subcat = $_REQUEST['subcat_id'];
$link = 'id='.$id.'&cat_id='.$cat'.&subcat_id='.$subcat;
$content = '<?php'.
'header("Location: [url]http://mysite.com/link.php?[/url]'.$link.'");'.
'?>'.
'<html><head><title></title></head><body>'.
'Redirecting...</body></html>';
$root_dir = $_SERVER['DOCUMENT_ROOT'].'/';
$new_dir = $root_dir.$dir;
$old_file = $root_dir.'/backup/template.php';
$old_index = $root_dir.'/backup/index.php';
$new_file = $root_dir.$dir.'index.php';
mkdir($new_dir);
copy($old_file, $old_index);
rename($old_index, $new_file);
if (!is_writable($new_file)) {
if(!chown($new_file, root)){
echo "Cannot change user!!";
};
if (!chmod($dir.$index, 0666)) {
echo "Cannot change the mode of file (".$dir.$index.")";
exit;
};
}
if(!$fp = @fopen($new_file, "w")){
echo "Can't open file (".$dir.$index.")";
exit;
}
if(!fwrite($new_file, $content)){
echo "Can't write to file.";
exit;
}
if (!fclose($fp)) {
echo "Cannot close file (".$new_file.")";
exit;
}
?>
Try that. I think the reason you got an error is because the php script wasn't working in the right folder. It's a possibility, but not promising anything.
Just reply if there are any problems.
~Brett