Template::ProcessFile PHP Method

ProcessFile() public static method

public static ProcessFile ( $p_tmpFile, $p_newFile, $p_charset = null )
    public static function ProcessFile($p_tmpFile, $p_newFile, $p_charset = null)
    {
        // remove existing file if one exists
        if (file_exists($p_newFile) && !is_dir($p_newFile)) {
            if (!unlink($p_newFile)) {
                return new PEAR_Error(camp_get_error_message(CAMP_ERROR_DELETE_FILE, $p_newFile), CAMP_ERROR_DELETE_FILE);
            }
        }
        $fileName = basename($p_newFile);
        $fileType = @mime_content_type($p_tmpFile);
        if (!empty($p_charset)) {
            if (strncmp($fileType, 'text', 4) == 0) {
                $success = self::ChangeCharset($p_tmpFile, $p_newFile, $fileType, $p_charset);
            } else {
                $success = rename($p_tmpFile, $p_newFile);
            }
            if (PEAR::isError($success) || !$success) {
                return $success;
            }
        } else {
            $success = rename($p_tmpFile, $p_newFile);
            if (!$success) {
                return new PEAR_Error(camp_get_error_message(CAMP_ERROR_CREATE_FILE, $fileName), CAMP_ERROR_CREATE_FILE);
            }
        }
        self::UpdateStatus();
        return true;
    }

Usage Example

Example #1
0
    exit;
}

$f_path = Input::Get('f_path', 'string', '');
$f_charset = Input::Get('f_charset', 'string', '');


$baseUpload = $Campsite['TEMPLATE_DIRECTORY'] . $f_path;
$backLink = "/$ADMIN/templates/upload_templ.php?Path=" . urlencode($f_path);

$nrOfFiles = isset($_POST['uploader_count']) ? $_POST['uploader_count'] : 0;
for ($i = 0; $i < $nrOfFiles; $i++) {
    $tmpnameIdx = 'uploader_' . $i . '_tmpname';
    $nameIdx = 'uploader_' . $i . '_name';
    $statusIdx = 'uploader_' . $i . '_status';
    if ($_POST[$statusIdx] == 'done') {
        $tmpFilePath = CS_TMP_TPL_DIR . DIR_SEP . $_POST[$tmpnameIdx];
        $newFilePath = $baseUpload . DIR_SEP . $_POST[$nameIdx];
        $result = Template::ProcessFile($tmpFilePath, $newFilePath, $f_charset);
    }
}

if ($result) {
    camp_html_add_msg(getGS('"$1" files uploaded.', $nrOfFiles), "ok");
    camp_html_goto_page("/$ADMIN/templates/?Path=" . urlencode($f_path));
} else {
    camp_html_add_msg($f_path . DIR_SEP . basename($newFilePath));
    camp_html_goto_page($backLink);
}

?>