Пример #1
0
 function file_dir_delete_recursive($path)
 {
     $result = FALSE;
     if ($path) {
         $file_prefix = '';
         if (substr($path, -1) == '*') {
             $file_prefix = basename($path, '*');
             $path = file_dir($path);
         }
         if (file_exists($path) && is_dir($path)) {
             $path = path_add_slash_end($path);
             if ($handle = opendir($path)) {
                 $result = TRUE;
                 while ($result && FALSE !== ($file = readdir($handle))) {
                     if ($file != "." && $file != "..") {
                         if ($file_prefix && substr($file, 0, strlen($file_prefix)) != $file_prefix) {
                             continue;
                         }
                         if (is_dir($path . $file)) {
                             $result = file_dir_delete_recursive($path . $file);
                         } else {
                             $result = @unlink($path . $file);
                         }
                     }
                 }
                 closedir($handle);
                 if (!$file_prefix && $result) {
                     $result = @rmdir($path);
                 }
             }
         }
     }
     return $result;
 }
            $err = 'Could not extract to ' . $archive_dir;
        } else {
            // move select files from the archive to media directory
            if (!file_move_extension('jpg', $archive_dir, $media_dir, $config)) {
                $err = 'Could not move jpg files from ' . $archive_dir . ' to ' . $media_dir;
            } else {
                if (!file_move_extension($config['export_audio_extension'], $archive_dir, $media_dir, $config)) {
                    $err = 'Could not move ' . $config['export_audio_extension'] . ' files from ' . $archive_dir . ' to ' . $media_dir;
                } else {
                    if (!file_move_extension($config['export_extension'], $archive_dir, $media_dir, $config)) {
                        $err = 'Could not move ' . $decoder_extension . ' files from ' . $archive_dir . ' to ' . $media_dir;
                    }
                }
            }
            // remove the temporary directory we created, and any remaining files (there shouldn't be any)
            file_dir_delete_recursive($archive_dir);
        }
    } else {
        if ($file_ext != $config['export_audio_extension'] && $file_ext != $config['export_extension']) {
            $err = 'invalid file extension ' . $file_ext;
        } else {
            if (!file_move_upload($file['tmp_name'], $path_without_extension . '.' . $file_ext)) {
                $err = 'Problem moving uploaded file';
            }
        }
    }
}
if (!$err) {
    // make sure we actually moved what we needed to, and change its permissions
    clearstatcache();
    if (!file_exists($path_without_extension . '.' . $config['export_extension'])) {
            case 'video':
                $frame_extension = 'jpg';
                // otherwise use image's original extension (eg. png)
            // otherwise use image's original extension (eg. png)
            case 'image':
                $encoder_fps = $config['import_fps'];
                if ($type == 'image') {
                    $encoder_fps = '1';
                }
                // move any frames
                $archive_path = path_concat($archive_dir, $config['import_dimensions'] . 'x' . $encoder_fps);
                if (file_exists($archive_path)) {
                    $media_path = path_concat($media_dir, $config['import_dimensions'] . 'x' . $encoder_fps);
                    if (!file_move_extension($frame_extension, $archive_path, $media_path, $config)) {
                        $err = 'Could not move ' . $frame_extension . ' files from ' . $archive_path . ' to ' . $media_path;
                    }
                }
                break;
        }
    }
    // remove the temporary directory we created, and any remaining files (there shouldn't be any)
    file_dir_delete_recursive($tmp_path);
}
if ($err) {
    header('HTTP/1.1: 400 Bad Request');
    header('Status: 400 Bad Request');
    print $err;
    log_file($err, $config);
} else {
    log_file($media_path, $config);
}