i am trying to upload image files. using following code. but getting error as
POST http://localhost/livestock/index.php/submitFile/ajaxFile 500 (Internal Server Error)
my javascirpt
function upload()
{
var input = document.getElementById("images");
var i = 0, len = input.files.length, img, reader, file;
for ( i; i < len; i++ ) {
file = input.files[i];
alert(file.name);
if (!!file.type.match(/image.*/)) {
if ( window.FileReader ) {
reader = new FileReader();
reader.onloadend = function (e) {
showUploadedItem(e.target.result, file.fileName);
};
reader.readAsDataURL(file);
}
if (formdata) {
formdata.append("images[]", file);
}
}
}
//alert(this.files.length);
if (formdata) {
var base=document.getElementById('asdf').value;
$.ajax({
url: base+"/index.php/submitFile/ajaxFile",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success:function (res) { alert('upload success'+res); //document.getElementById("response").innerHTML = res;
},
error:function (res) { alert('upload failed'+res);
//document.getElementById("response").innerHTML = res;
}
});
}
}
php page
foreach ($_FILES["images"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$name = $_FILES["images"]["name"][$key];
move_uploaded_file( $_FILES["images"]["tmp_name"][$key], "$base/../asdf/" . $_FILES['images']['name'][$key]);
$error1=$error1.'<br>'.$error;
}
}
return true;
if i only write return true
in php file , getting response as file uploaded successfully otherwise getting error as mentioned , i think its problem with java script code formdata.append("images[]", file); new to jquery , kindly advise to solve the issue, thanks in advance.
Hi, file uploading successfully with the above code. but showing upload failed because , error_reporting(0);
was not there in php script.