Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
139
rated 0 times [  142] [ 3]  / answers: 1 / hits: 15568  / 11 Years ago, fri, september 13, 2013, 12:00:00

I am uploading files using jQuery.ajax and everything works perfect in modern browsers like Google Chrome, Mozilla Firefox, Opera, except of Internet Explorer 10.



new FormData($('.uploadForm')[0]) doesnt work in IE10, but if I only try with this piece of code: new FormData($('.uploadForm')) it works...Looks like it does not accept elements at specific index or something? I dont understand this realy good, that is the reason, why I am searching for help.



Does it exist any kind of workaround for this example for IE10?



JS:



var form = new FormData($('.uploadForm')[0]);
config.progressBar.progressWidth = 0;
$('.uploadForm .valueBox').fadeOut('slow',function(){
$(this).addClass('hidden')
$('.meter').removeClass('hidden').width(config.progressBar.width);
$.ajax({
url: '../../uploads/some.php',
type: 'POST',
xhr: function() {
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){
myXhr.upload.onprogress = progress;
}
return myXhr;
},
success: function (res) {
console.log(res)
},
data: form,
cache: false,
contentType: false,
processData: false
});


Peace of some.php code:



foreach($_FILES[file][error] as $key => $value) {
if ($value == UPLOAD_ERR_OK){

$name = $_FILES[file][name][$key];

$arr_files = getimagesize($_FILES[file][tmp_name][$key]);
$width = $arr_files[0];
$height = $arr_files[1];
$mime = $arr_files['mime'];

copy($_FILES['file']['tmp_name'][$key], '../uploads/upload/'.$name);

echo json_encode($_FILES);
}
}


IE10 error thrown: SCRIPT5: Access is denied.


More From » php

 Answers
12

Don't pass the files into the constructor, but use append, like:



var formData = new FormData();
formData.append('file', $('input[type=file]')[0].files[0]);

[#75707] Thursday, September 12, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maxd

Total Points: 568
Total Questions: 100
Total Answers: 101

Location: Serbia
Member since Tue, Jul 26, 2022
2 Years ago
;