加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 通过ajax从input type = file发送原始文件数据

发布时间:2020-12-13 16:43:33 所属栏目:PHP教程 来源:网络整理
导读:我有一个简单的形式: form enctype="multipart/form-data" id="imageupload" input name="files" type="file" / input type="button" value="Upload" //form 现在我想用ajax请求发送所有文件. 此示例有效,但它有一个错误.在我保存的文件中,还有其他信息: -
我有一个简单的形式:

<form enctype="multipart/form-data" id="imageupload">
   <input name="files" type="file" />
   <input type="button" value="Upload" />
</form>

现在我想用ajax请求发送所有文件.

此示例有效,但它有一个错误.在我保存的文件中,还有其他信息:

-----------------------------169443243924626
Content-Disposition: form-data; name="files"; filename="shelby.png"
Content-Type: image/png


       $.ajax({
       url: 'imageupload.php',//server script to process data
       type: 'POST',xhr: function() {  // custom xhr
           myXhr = $.ajaxSettings.xhr();
           if(myXhr.upload){ // check if upload property exists
               myXhr.upload.addEventListener('progress',progressHandlingFunction,false); // for handling the progress of the upload
           }
           return myXhr;
       },//Ajax events
       //beforeSend: beforeSendHandler,//success: completeHandler,//error: errorHandler,// Form data
       data: new FormData($('#imageupload')[0]),//Options to tell JQuery not to process data or worry about content-type
       cache: false,contentType: 'multipart/form-data',processData: false
   });

现在我开始说:

$('#imageupload')[0].files.files[0]

我可以.我得到这个名字.但是如何获取原始文件数据?

解决方法

try this

 $filename =  $_FILES['ur_image']['name'] ;
 $filesize =  $_FILES['ur_image']['size']; 
 $erro     =  $_FILES['ur_image']['error']; //checks UPLOAD_ERR_OK
 $tmpname  = $_FILES['ur_image']['tmp_name'];              
 $dest     = ROOT_DIR.'/upload/logo/';

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读