note 55200 added to function.move-uploaded-file
| From: | espiao at gmail dot com | Date: | Wed, 27 Jul 2005 14:25:30 +0000 |
| Subject: | note 55200 added to function.move-uploaded-file | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-92559@lists.php.net to get a copy of this message | ||
/**
* This function moves the archives and directoryes of a directory of
* origin for a directory destination being able replace them or not.
**/
function mvdir($oldDir, $newDir, $replaceFiles = true) {
if ($oldDir == $newDir) {
trigger_error("Destination directory is equal of origin.");
return false;
}
if (!($tmpDir = opendir($oldDir))) {
trigger_error("It was not possible to open origin directory.");
return false;
}
if (!is_dir($newDir)) {
trigger_error("It was not possible to open destination directory.");
return false;
}
while (($file = readdir($tmpDir)) !== false) {
if (($file != ".") && ($file !== "..")) {
$oldFileWithDir = $oldDir . $file;
$newFileWithDir = $newDir . $file;
if (is_dir($oldFileWithDir)) {
@mkdir($newFileWithDir."/", 0777);
@mvdir($oldFileWithDir."/", $newFileWithDir."/", $replaceFiles);
@rmdir($oldFileWithDir);
}
else {
if (file_exists($newFileWithDir)) {
if (!$replaceFiles) {
@unlink($oldFileWithDir);
continue;
}
}
@unlink($newFileWithDir);
@copy($oldFileWithDir, $newFileWithDir);
@chmod($newFileWithDir, 0777);
@unlink($oldFileWithDir);
}
}
}
return true;
}
/**
* This is an example of move with replace files on destination folder if
* exists files with the same names on destionatio folder
**/
mvdir("/var/www/example/", "/var/www/other_folder/");
/**
* This is an example of move without replace files on destination
* folder if exists files with the same names on destionatio folder
**/
mvdir("/var/www/example/", "/var/www/other_folder/", false);
----
Manual Page -- http://www.php.net/manual/en/function.move-uploaded-file.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+55200
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55200&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55200&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55200&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55200&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55200&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55200&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+55200&report=yes
Search -- http://master.php.net/manage/user-notes.php