themoose
November 19th, 2005, 15:03
I need to have a script that copies one directory to another directory. Here is the script i have atm but it does not work. Any help is gratefully accepted!
I have chmoded this 777
<form action="script.php">
<input type="text" name="source" value="Source">
<input type="text" name="dest" value="Destination">
<input type="Submit" value="Submit">
</form>
<?php
/**
* Copy a file, or recursively copy a folder and its contents
*
* @author Aidan Lister <aidan@php.net>
* @version 1.0.1
* @param string $source Source path
* @param string $dest Destination path
* @return bool Returns TRUE on success, FALSE on failure
*/
$source = stripslashes($_POST['source']);
$dest = stripslashes($_POST['dest']);
function copyr($source, $dest)
{
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
if ($dest !== "$source/$entry") {
copyr("$source/$entry", "$dest/$entry");
}
}
// get the current permissions from the source file or directory
$perms = substr(sprintf('%o', fileperms("$source/$entry")), -4);
// Change the permissions on the destination file or folder
chmod ("$dest/$entry", $perms);
// Clean up
$dir->close();
return true;
}
?>
i did some homebrew editing so im not sure if that'll work.
thanks
I have chmoded this 777
<form action="script.php">
<input type="text" name="source" value="Source">
<input type="text" name="dest" value="Destination">
<input type="Submit" value="Submit">
</form>
<?php
/**
* Copy a file, or recursively copy a folder and its contents
*
* @author Aidan Lister <aidan@php.net>
* @version 1.0.1
* @param string $source Source path
* @param string $dest Destination path
* @return bool Returns TRUE on success, FALSE on failure
*/
$source = stripslashes($_POST['source']);
$dest = stripslashes($_POST['dest']);
function copyr($source, $dest)
{
// Simple copy for a file
if (is_file($source)) {
return copy($source, $dest);
}
// Make destination directory
if (!is_dir($dest)) {
mkdir($dest);
}
// Loop through the folder
$dir = dir($source);
while (false !== $entry = $dir->read()) {
// Skip pointers
if ($entry == '.' || $entry == '..') {
continue;
}
// Deep copy directories
if ($dest !== "$source/$entry") {
copyr("$source/$entry", "$dest/$entry");
}
}
// get the current permissions from the source file or directory
$perms = substr(sprintf('%o', fileperms("$source/$entry")), -4);
// Change the permissions on the destination file or folder
chmod ("$dest/$entry", $perms);
// Clean up
$dir->close();
return true;
}
?>
i did some homebrew editing so im not sure if that'll work.
thanks