コード例 #1
0
ファイル: functions.php プロジェクト: ilkinium/btec.dev
function DoUpload($field = 'userfile')
{
    $output = array();
    $output["success"] = true;
    $output["is_pdf"] = 0;
    if (isset($_SESSION["tinymce_upload_directory"]) and $_SESSION["tinymce_upload_directory"] != "") {
        $current_folder = $_SESSION["tinymce_upload_directory"];
    } else {
        $current_folder = LIBRARY_FOLDER_PATH;
    }
    if (!CanAcessUploadForm()) {
        $output["reason"] = lang('no_permission_to_upload');
        $output["success"] = false;
        return $output;
    }
    if (!isset($_FILES[$field])) {
        $output["reason"] = lang('file_not_selected');
        $output["success"] = false;
        return $output;
    }
    if (!is_uploaded_file($_FILES[$field]['tmp_name'])) {
        $error = !isset($_FILES[$field]['error']) ? 4 : $_FILES[$field]['error'];
        $output["success"] = false;
        switch ($error) {
            case 1:
                // UPLOAD_ERR_INI_SIZE
                $output["reason"] = lang('file_exceeds_limit_size');
                break;
            case 2:
                // UPLOAD_ERR_FORM_SIZE
                $output["reason"] = lang('file_exceeds_limit_size');
                break;
            case 3:
                // UPLOAD_ERR_PARTIAL
                $output["reason"] = lang('file_uploaded_partially');
                break;
            case 4:
                // UPLOAD_ERR_NO_FILE
                $output["reason"] = lang('file_not_selected');
                break;
            case 6:
                // UPLOAD_ERR_NO_TMP_DIR
                $output["reason"] = lang('no_temp_directory');
                break;
            case 7:
                // UPLOAD_ERR_CANT_WRITE
                $output["reason"] = lang('unable_to_write_the_file');
                break;
            case 8:
                // UPLOAD_ERR_EXTENSION
                $output["reason"] = lang('invalid_extension');
                break;
            default:
                $output["reason"] = lang('file_not_selected');
                break;
        }
        return $output;
    }
    if (!ValidFileExtension($_FILES[$field]['name'])) {
        $output["reason"] = lang('invalid_extension');
        $output["success"] = false;
        return $output;
    }
    if (RENAME_UPLOADED_FILES == true) {
        $file_name = random_file_name($_FILES[$field]['name']);
        $file_name = set_filename($current_folder, $file_name);
    } else {
        $file_name = set_filename($current_folder, $_FILES[$field]['name']);
    }
    if (!@copy($_FILES[$field]['tmp_name'], $current_folder . $file_name)) {
        if (!@move_uploaded_file($_FILES[$field]['tmp_name'], $current_folder . $file_name)) {
            $output["reason"] = lang('could_not_move_file');
            $output["success"] = false;
            return $output;
        }
    }
    if (!isset($_SESSION['SimpleImageManager'])) {
        $_SESSION['SimpleImageManager'] = array();
    }
    $_SESSION['SimpleImageManager'][] = PathToUrl($current_folder) . $file_name;
    $output["file"] = PathToUrl($current_folder) . $file_name;
    if (is_image_extenstion(GetExtension($file_name))) {
        Resizing($current_folder, $file_name);
    } else {
        $output["is_pdf"] = 1;
        $output["icon"] = get_file_icon_path(GetExtension($file_name));
    }
    return $output;
}
コード例 #2
0
function DoUpload($field = 'userfile')
{
    $output = array();
    $output["success"] = true;
    if (isset($_SESSION["tinymce_upload_directory"]) and $_SESSION["tinymce_upload_directory"] != "") {
        $current_folder = $_SESSION["tinymce_upload_directory"];
    } else {
        $current_folder = LIBRARY_FOLDER_PATH;
    }
    if (!CanAcessUploadForm()) {
        $output["reason"] = "No permission to upload.";
        $output["success"] = false;
        return $output;
    }
    if (!isset($_FILES[$field])) {
        $output["reason"] = "File not selected.";
        $output["success"] = false;
        return $output;
    }
    if (!is_uploaded_file($_FILES[$field]['tmp_name'])) {
        $error = !isset($_FILES[$field]['error']) ? 4 : $_FILES[$field]['error'];
        $output["success"] = false;
        switch ($error) {
            case 1:
                // UPLOAD_ERR_INI_SIZE
                $output["reason"] = "File exceeds limit size.";
                break;
            case 2:
                // UPLOAD_ERR_FORM_SIZE
                $output["reason"] = "File exceeds limit size.";
                break;
            case 3:
                // UPLOAD_ERR_PARTIAL
                $output["reason"] = "File uploaded partially.";
                break;
            case 4:
                // UPLOAD_ERR_NO_FILE
                $output["reason"] = "File not selected.";
                break;
            case 6:
                // UPLOAD_ERR_NO_TMP_DIR
                $output["reason"] = "No temp directory.";
                break;
            case 7:
                // UPLOAD_ERR_CANT_WRITE
                $output["reason"] = "Unable to write the file.";
                break;
            case 8:
                // UPLOAD_ERR_EXTENSION
                $output["reason"] = "Invalid extension.";
                break;
            default:
                $output["reason"] = "File not selected.";
                break;
        }
        return $output;
    }
    if (!ValidFileExtension($_FILES[$field]['name'])) {
        $output["reason"] = "Invalid extension.";
        $output["success"] = false;
        return $output;
    }
    $file_name = set_filename($current_folder, $_FILES[$field]['name']);
    if (!@copy($_FILES[$field]['tmp_name'], $current_folder . $file_name)) {
        if (!@move_uploaded_file($_FILES[$field]['tmp_name'], $current_folder . $file_name)) {
            $output["reason"] = "Could not move file.";
            $output["success"] = false;
            return $output;
        }
    }
    if (!isset($_SESSION['SimpleImageManager'])) {
        $_SESSION['SimpleImageManager'] = array();
    }
    $_SESSION['SimpleImageManager'][] = PathToUrl($current_folder) . $file_name;
    $output["file"] = PathToUrl($current_folder) . $file_name;
    return $output;
}