seagull的publisher模块下面有提供一个上传文件的功能,但是上传后,文件名是中文的文件名称会变成乱码。在FF中进行下载时提示是正常的,但是在IE下就是不正常的。后来发现:
在window系统下,如果你将上传的文件保存时,如果文件名是使用utf-8编码,则会以乱码显示的。只能使用GBK。
同样,在下载时进行读取时,也要使用GBK来进行,否则会读取不到文件而变成空文件。
function _cmd_add(&$input, &$output)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
$output->docCatID = $input->docCatID;
$output->template = 'documentMgrAdd.html';
if ($input->submitted) { // if file uploaded
// check id dir exists, create if not
if (!is_writable(SGL_UPLOAD_DIR)) {
require_once 'System.php';
$success = System::mkDir(array(SGL_UPLOAD_DIR));
if (!$success) {
SGL::raiseError('The upload directory does not appear to be writable, please give the
webserver permissions to write to it', SGL_ERROR_FILEUNWRITABLE);
return false;
}
}
//copy($_FILES['assetFile']['tmp_name'], SGL_UPLOAD_DIR . '/' . $input->assetFileName);
copy($_FILES['assetFile']['tmp_name'], SGL_UPLOAD_DIR . '/' . iconv('UTF-8','GBK',$input->assetFileName));
$output->save = "true";
$output->assetTypeID = $this->_mime2AssetType($input->assetFileType);
$output->document->mime_type = $input->assetFileType;
$output->document->document_type_id = $output->assetTypeID;
function _cmd_downloadZipped(&$input, &$output)
{
SGL::logMessage(null, PEAR_LOG_DEBUG);
// for the case PHP is compiled without gzip support
// redirect to standard download method
if (!function_exists('gzcompress')) {
return SGL::raiseError('You need PHP compiled with zlib to use this feature',
SGL_ERROR_INVALIDCALL);
}
require_once SGL_LIB_DIR . '/other/Zip.php';
$document = $this->getDocument($input->assetId);
if (PEAR::isError($document)) {
return $document;
}
//添加下面这行
$name = iconv('UTF-8','GBK',$document->name);
//$fileName = SGL_UPLOAD_DIR . '/' . $document->name;
$fileName = SGL_UPLOAD_DIR . '/' . $name;
$buffer = file_get_contents($fileName);
$zip = & new Zip();
$zip->addFile($buffer, basename($fileName));
$fileData = $zip->file();
$download = &new SGL_Download();
$download->setData($fileData);
$download->setContentType('application/zip');
// $download->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $document->name . '.zip');
$download->setContentDisposition(HTTP_DOWNLOAD_ATTACHMENT, $name . '.zip');
$download->setAcceptRanges('none');
$download->setContentTransferEncoding('binary');