Example #1
0
$func = $_POST['action'] == 'move' ? 'rename' : 'copy';
if (!file_exists($toDir)) {
    $return['error'] = true;
    $return['errorText'] = "The directory <code>{$_POST['toDir']}</code> does not exist.";
} else {
    if (count($_POST['files']) < 1) {
        $return['error'] = true;
        $return['errorText'] = 'There were no files to copy.';
    } else {
        $return['errorText'] = '<ol>';
        foreach ($_POST['files'] as $file) {
            $source = IMAGEBASEDIR . $file;
            $is_dir = is_dir($source);
            $name = basename($file);
            $is_img = substr($name, -4) == '.tem' || $is_dir ? false : true;
            $destination = check_file_duplicate($toDir . $name);
            $return['source'] = $source;
            $return['destination'] = $destination;
            $return['is_dir'] = $is_dir ? 'yes' : 'no';
            if (!file_exists($source)) {
                $return['error'] = true;
                $return['errorText'] .= "<li>The file <code>{$file}</code> does not exist.</li>";
            } else {
                if (file_exists($destination)) {
                    $return['error'] = true;
                    $return['errorText'] .= "<li>The file <code>{$_POST['toDir']}/{$name}</code> already exists, so <code>{$file}</code> was not copied.</li>";
                } else {
                    if (!($is_dir && $func == 'copy') && !$func($source, $destination)) {
                        $return['error'] = true;
                        $return['errorText'] .= "<li>The file <code>{$file}</code> could not be copied to <code>{$_POST['toDir']}/{$name}</code>.</li>";
                    } else {
Example #2
0
 foreach ($_POST['files'] as $name) {
     $ext = pathinfo($name, PATHINFO_EXTENSION);
     preg_match("/^\\d{1,11}\\//", $name, $project);
     $project = str_replace('/', '', $project[0]);
     if (!in_array($project, $_SESSION['projects'])) {
         $return['error'] = true;
         $return['errorText'][$name] = 'unauthorised to change project ' . $project;
     } else {
         if (!in_array($ext, $allowed_ext)) {
             $return['error'] = true;
             $return['errorText'][$name] = 'exists, extension undeleteable';
         } else {
             $file = IMAGEBASEDIR . $name;
             $db_name = $name;
             $path = pathinfo($file);
             $destination = check_file_duplicate(IMAGEBASEDIR . $project . "/.trash/" . $path['filename'] . '.' . $path['extension']);
             $return['dest'][] = $destination;
             if (!file_exists($file)) {
                 $return['error'] = true;
                 $return['errorText'][$db_name] = 'does not exist';
             } else {
                 if (!underPath($file)) {
                     $return['error'] = true;
                     $return['errorText'][$db_name] = 'is not in your image path';
                 } else {
                     if (!rename($file, $destination)) {
                         $return['error'] = true;
                         $return['errorText'][$db_name] = 'could not be deleted';
                     } else {
                         if ($ext == 'jpg') {
                             // delete database entry if it is an image
Example #3
0
function check_file_duplicate($f, $n = 0)
{
    if (file_exists($f)) {
        // file already exists, so save as a copy
        $path = pathinfo($f);
        if ($n > 0) {
            $newfile = $path['dirname'] . '/' . preg_replace("/_copy\\d*\$/", "_copy" . $n, $path['filename']) . ($path['extension'] == '' ? '' : '.') . $path['extension'];
        } else {
            $newfile = $path['dirname'] . '/' . $path['filename'] . '_copy' . ($path['extension'] == '' ? '' : '.') . $path['extension'];
        }
        $n++;
        return check_file_duplicate($newfile, $n);
    } else {
        return $f;
    }
}