louyaoluan 发表于 2018-12-21 09:47:19

PHP+jquery+ajaxupload 无刷新上传文件或图片

  PHP+jquery+ajaxupload 无刷新上传文件或图片
  我参照了网上其它的方法,其它人写的都存在一些问题。我进行了些修正。
  上传文件更改文件名,防止文件重名。
  第一步:包含这个;jquery库文件 和;ajaxupload库文件。
  自己上网下吧,有很多。
  第二步:php上传类file_upload.php
  
第三步 类调用方法页 upload.php
  

  第四步 页面实现 add.php
  图片上传以后,直接显示预览图片。
  
   
    景点管理
      
      
      
      
      
      $(document).ready(function(){
    var button = $('#upload_button'), interval;
    var fileType = "pic",fileNum = "one";
    new AjaxUpload(button,{
      action: 'upload.php',
      name: 'userfile',
      onSubmit : function(file, ext){
            if(fileType == "pic")
            {
                if (ext && /^(jpg|png|jpeg|gif)$/.test(ext)){
                  this.setData({
                        'info': '文件类型为图片'
                  });
                } else {
                  button.text('非图片类型文件,重新上传');
                  return false;               
                }
            }
            $("#pic_path").val(file);            
            button.text('文件上传中');
            
            if(fileNum == 'one')
                this.disable();
            interval = window.setInterval(function(){
                var text = button.text();
                if (text.length < 14){
                  button.text(text + '.');                  
                } else {
                  button.text('文件上传中');            
                }
            }, 200);
      },
      onComplete: function(file, response){
            if(response.indexOf(&quot;success&quot;)
页: [1]
查看完整版本: PHP+jquery+ajaxupload 无刷新上传文件或图片