首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Uploadify文件上传

Uploadify文件上传
EN

Stack Overflow用户
提问于 2011-04-09 16:12:08
回答 6查看 7.1K关注 0票数 1

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

请帮帮我。

我使用以下设置:

代码语言:javascript
复制
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);
    }

..。

谢谢!

EN

回答 6

Stack Overflow用户

发布于 2011-04-09 16:19:34

将当前选项更改为:

代码语言:javascript
复制
$('#file_upload').uploadify({
    'uploader'    : '/uploadify/uploadify.swf',
    'script'      : '/uploadify/uploadify.php',
    'cancelImg'   : '/uploadify/cancel.png',
    'folder'      : '/uploads',
    'fileTypeExt'     : '*.jpg;*.gif;*.png',  <== this line
    'fileTypeDesc'    : 'Image Files'
});

参考:http://www.uploadify.com/documentation/uploadify/filetypeexts/

票数 0
EN

Stack Overflow用户

发布于 2011-04-09 16:20:01

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

票数 0
EN

Stack Overflow用户

发布于 2011-04-10 06:28:14

代码语言:javascript
复制
var settingObject = {
    'uploader'  : '/uploadify/uploadify.swf',   // set your path
    'checkScript':'/uploadify/check.php',    // set your path
    'script'    : '/uploadify/uploadify.php',   // set your path
    'cancelImg' : '/uploadify/cancel.png',   // set your path
    'folder'    : '/files/useruploads',
    'auto'      : true,
    'fileExt'   : '*.jpg;*.gif;*.png;*.txt;*.pdf;*.doc;*.docx',   // any extension you want to allow
    'fileDesc'  : 'Upload Files (.JPG, .GIF, .PNG, .TXT, .PDF, .DOC, .DOCX)',
    'removeCompleted': false
  };

$("#file-1").uploadify(settingObject);

参考:(文件扩展名) http://www.uploadify.com/documentation/options/fileext/

这应该适用于你..。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5606142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档