seagull -- 上传文件后下载时文件名是乱码

14 篇文章 0 订阅

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');

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值