本文介绍了Uploadify文件上传的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用uploadify上传pdf或txt文件,但没有成功. Uploadify 2.1.4仅上传图像文件.我试图只是重命名文件扩展名,试图允许.,试图允许pdf或其他格式,但是Uploadify只上传F ****** g图像,我不知道为什么.

i am trying to use uploadify, to upload pdf or txt files, but without success. Uploadify 2.1.4 uploads just image files. I tried to just rename file extensions, tried to allow ., tried to namely allow pdf or other formats, but Uploadify uploads just F******g images and i do not know why...

请帮助我.

我使用以下设置:

public function show()
{
        if(!$this->dir) throw new exception("Upload dir is not set");
        if(!$this->url) throw new exception("Upload url is not set");

        $rem=(isset($_POST[$this->name."-rem"]))?$_POST[$this->name."-rem"]:"";
        $tpl='<div id="'.$this->name.'-queue" class="upload-queue">'.$this->fillQueue().'</div>';
        $tpl.='<input id="'.$this->name.'-uploadify" name="'.$this->name.'-uploadify" type="file" />';
        $tpl.='<input id="'.$this->name.'-files" name="'.$this->name.'-files" type="hidden" />';
        $tpl.='<input id="'.$this->name.'-rem" name="'.$this->name.'-rem" type="hidden" value="'.$rem.'"/>';
        //$tpl.='<link rel="stylesheet" type="text/css" href="/uploadify/uploadify.css" />';
        $tpl.="<script type=\"text/javascript\"><!--
        var ".$this->name."Files=".$this->currentCount.";
        function ".$this->name."DeleteFile(where)
        {
            var rem=$('#".$this->name."-rem').val();
            if(rem!='') rem+=',';
            $('#".$this->name."-rem').val(rem+$(where).parent().attr('id'));
            $(where).parent().remove();
            ".$this->name."Files--;
            if(".$this->name."Files<".$this->count.") $(\"#".$this->name."-uploadifyUploader\").show();
        }
        $(document).ready(function() {
        $(\"#".$this->name."-uploadify\").uploadify({
            'uploader'       : '/uploadify/uploadify.swf',
            'script'         : '".$this->url."',
            'scriptData'     : {'".session_name()."':'".session_id()."'},
            'cancelImg'      : '/uploadify/cancel.png',
            'folder'         : '".$this->dir."/thumb',
            'queueID'        : '".$this->name."-queue',
            'auto'           : true,
            'multi'          : ".(($this->count>1)?"true":"false").",
            'buttonText'     : '".$this->buttonName."',
            'fileExt'        : '".rtrim($this->fileExt,";")."',
            'fileDesc'       : '".rtrim($this->fileDesc,",")."',
            onError          : function (a, b, c, d) {
                                 if (d.status == 404)
                                    alert('Could not find upload script. Use a path relative to: '+'<?= getcwd() ?>');
                                 else if (d.type === \"HTTP\")
                                    alert('error '+d.type+\": \"+d.status);
                                 else if (d.type ===\"File Size\")
                                    alert(c.name+' '+d.type+' Limit: '+Math.round(d.sizeLimit/1024)+'KB');
                                 else
                                    alert('error '+d.type+\": \"+d.text);
                                },
            onComplete       : function(event, queueID, fileObj, response, data){
                                $(\"#".$this->name."-queue\").append('<div id=\"'+fileObj.filePath+'\" class=\"item\"><div style=\"background: url('+fileObj.filePath+') no-repeat 50% 50%\"></div><img src=\"/uploadify/cancel.png\" class=\"delete-file\" onclick=\"".$this->name."DeleteFile(this);\"></div>');
                                $('#".$this->name."-queue').sortable('refresh');
                                ".$this->name."Files++;
                                if(".$this->name."Files>=".$this->count.") $(\"#".$this->name."-uploadifyUploader\").hide();
                                },
            onInit           : function(){setTimeout(function(){if(".$this->name."Files>=".$this->count.") $(\"#".$this->name."-uploadifyUploader\").hide();},500);}
        });
    $('#".$this->name."-queue').sortable();
    $('#".$this->name."-queue').disableSelection();
    $('form').submit(function(){
        $('#".$this->name."-files').val($('#".$this->name."-queue').sortable('toArray'));
    });
});
--></script>";

        return array("",$tpl);
    }

...

谢谢!

推荐答案

使用'fileExt' : '*.pdf;*.jpg;*.jpeg;*.png',代替读取它的文件名.

Use 'fileExt' : '*.pdf;*.jpg;*.jpeg;*.png', instead of the filename that reads it.

这篇关于Uploadify文件上传的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-23 21:35