上传文件上传

问题描述 投票:1回答:6

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

请帮我。

我使用这些设置:

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

...

谢谢!

php jquery uploadify
6个回答
0
投票
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
投票

每个文件可能存在大小限制问题。尝试添加以下内容

'sizeLimit': 500000

0
投票

尝试在你的upload_max_filesize中编辑php.ini


0
投票

将您当前的选项更改为:

$('#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
投票

改变这些行:

'fileTypeExt'        : '*.txt;*.pdf;',
'fileTypeDesc'       : '*.txt and *.pdf',

0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.