PDA

View Full Version : Help!



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

ciprian@terra-bit
November 19th, 2005, 18:42
You forgot 1 MOST IMPORTANT and VITAL thing for POSTING files.

enctype=multipart/form-data

Istead of


<form action="script.php">
<input type="text" name="source" value="Source">
<input type="text" name="dest" value="Destination">
<input type="Submit" value="Submit">
</form>


You should have had


<form action="script.php" enctype=multipart/form-data>
<input type="text" name="source" value="Source">
<input type="text" name="dest" value="Destination">
<input type="Submit" value="Submit">
</form>

themoose
November 20th, 2005, 03:38
okay thanks, but it still will not work. Alternative scripts are also useful anybody?

ciprian@terra-bit
November 20th, 2005, 05:55
Well mate I thought you might figure it out...

But you have another TOO OBVIOUS issue with your current script

The form has TEXT fields that are holding FILES man

So... INSTEAD OF:


<form action="script.php" enctype=multipart/form-data>
<input type="text" name="source" value="Source">
<input type="text" name="dest" value="Destination">
<input type="Submit" value="Submit">
</form>


YOU SHOULD TRY


<form action="script.php" enctype="multipart/form-data">
Source: <input type="file" name="source"><br>
Destination: <input type="file" name="dest"><p>
<input type="Submit" value="Submit">
</form>


Thanks
CD

themoose
November 20th, 2005, 06:15
thanks but i think you got the idea of the script wrong. Its supposed to copy one folder on the server to another. That form is just to get the variables right.