【问题标题】:Uploadify file uploadingUploadify 文件上传
【发布时间】:2023-03-29 15:55:01
【问题描述】:

我正在尝试使用 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 和 JS 交织在一起。哪一个给你错误?

标签: php jquery uploadify


【解决方案1】:
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/

这应该对你有用..

【讨论】:

  • @[muneer]这也将在选择'image'作为文件类型时上传.txt文件。选择“文件”作为文件类型时,如何允许选择.txt文件?
【解决方案2】:

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

'sizeLimit': 500000

【讨论】:

    【解决方案3】:

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

    【讨论】:

      【解决方案4】:

      将您当前的选项更改为这些:

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

      【讨论】:

      • 我知道有 fileExt 标志,我尝试将其删除,我尝试将其重写为 pdf、doc、docx 等,但它只上传图像文件,没有其他...这就是为什么我写在这里寻求帮助...
      • 第一个demo上传.,但是不知道是不是在那个服务器上成功上传了,第二个demo只上传图片,但是设置为只上传图片。 ..
      • @[Efazati]This will also upload .txt files when 'Image' is selected as the file type.选择“文件”作为文件类型时,如何允许选择.txt文件?
      【解决方案5】:

      更改这些行:

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

      【讨论】:

      • @[Somnath Muluk] This will also upload .txt files when 'Image' is selected as the file type.选择“文件”作为文件类型时,如何允许选择.txt文件?
      • @Zesty:他说“我正在尝试使用uploadify,上传pdf或txt文件”所以允许的文件扩展名应该是.txt、.pdf
      • @[Somnath Muluk] 我并没有不同意您的解决方案。我只是问你是否知道如何添加多个文件类型,如数组或其他东西。如果能够在下拉列表中有多个选择,那就太好了。不过,我不确定这是否可能。
      • @Zesty:是的,你是对的。需要在“fileExt”中提及所需的文件类型。我认为是不可能通过提供数组来实现的。
      【解决方案6】:

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

      【讨论】:

      • @[pufos]这也将在选择'image'作为文件类型时上传.txt文件。选择“文件”作为文件类型时,如何允许选择.txt文件?
      猜你喜欢
      • 2013-04-01
      • 2012-11-30
      • 1970-01-01
      • 2013-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多