Попробуйте с этим кодом, пожалуйста:
$(document).ready(function(){
$('#your_form').on('submit', function(event){
event.preventDefault();
$.ajax({
url:"banner_data/upload_remove_files",
method:"POST",
data: new FormData(this),
dataType:'JSON',
contentType: false,
cache: false,
processData: false,
success:function(data)
{
if(data.msg != 'error' && self.hasClass('remove_class')) {
alert('File Uploaded');
}
},
error:function(data){
console.log(data);
}
})
});
});
И используйте такую форму:
<form id="your_form" method="POST" enctype="multipart/form-data">
<input type="file" name="image">
<input type="submit" name="submit" value="Upload">
</form>
А о вашем коде PHP :
// SET A DEFAULT VALUES
$msg = 'error';
$result = '';
if (isset($_POST['submit'])) {
$file = $_FILES['file'];
$fileName = $file['name'];
$fileTmpName = $file['tmp_name'];
$fileSize = $file['size'];
$fileError = $file['error'];
$fileType = $file['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
# VERIFY YOUR FILE HERE
if ($fileError != 0) {
$msg = "error";
}
# UPLOAD ...
clearstatcache();
$fileNewName = uniqid(true).".".$fileActualExt; // GENERATE NAME FOR THIS FILE
$fileDestination = 'your_path/'.$fileNewName;
if (move_uploaded_file($fileTmpName, $fileDestination)) {
$msg = "Good ...";
$result = "File Path : ".$fileDestination;
}
}
echo '['.json_encode(['msg' => $msg, 'file_name' => $result]).']';
И если вы не можете отправить большой размер файла т.е. более 1 МБ ... Просто измените php.ini
:
post_max_size = 256M
upload_max_filesize = 1000M