JavaScript — перетащить все типы файлов на веб-приложение

Мне нужно добавить на моем сайте перетащить & функция удаления, которая позволяет загружать все типа файлов (pdf, jpg, txt и т. д.).

А также Мне нужна функция для хранения этого файла в определенном каталоге.

Я нашел этот код в сети, но он позволяет только загружать изображения (jpg, png и т. Д.).

var fileobj;
function upload_file(e) {
e.preventDefault();
fileobj = e.dataTransfer.files[0];
ajax_file_upload(fileobj);
}

function file_explorer() {
document.getElementById('selectfile').click();
document.getElementById('selectfile').onchange = function() {
fileobj = document.getElementById('selectfile').files[0];
ajax_file_upload(fileobj);
};
}

function ajax_file_upload(file_obj) {
if(file_obj != undefined) {
var form_data = new FormData();
form_data.append('file', file_obj);
$.ajax({
type: 'POST',
url: 'ajax.php',
contentType: false,
processData: false,
data: form_data,
success:function(response) {
alert(response);
$('#selectfile').val('');
}
});
}
}

#drop_file_zone {
background-color: #EEE;
border: #999 5px dashed;
width: 290px;
height: 200px;
padding: 8px;
font-size: 18px;
}

#drag_upload_file {
width:50%;
margin:0 auto;
}

#drag_upload_file p {
text-align: center;
}

#drag_upload_file #selectfile {
display: none;
}
<html>
<head>
<meta charset="utf-8">
<meta name="generator" content="AlterVista - Editor HTML"/>
<title></title>
</head>
<body>
<div id="drop_file_zone" ondrop="upload_file(event)" ondragover="return false">

<div id="drag_upload_file">

<p>Drop file here</p>

<p>or</p>

<p><input type="button" value="Select File" onclick="file_explorer();"></p>

<input type="file" id="selectfile">

</div>

</div>


</body>
</html>

0

Решение

Задача ещё не решена.

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector