Answer the question
In order to leave comments, you need to log in
How to write a file receiving handler in QT?
The task is to upload a file via a form to a web server. Found the following code online:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
</head>
<body>
<form name="uploader" enctype="multipart/form-data" method="POST">
Отправить этот файл: <input name="userfile" type="file" />
<button type="submit" name="submit">Загрузить</button>
</form>
</body>
</html>
<script type="text/javascript">
$("form[name='uploader']").submit(function(e) {
var formData = new FormData($(this)[0]);
$.ajax({
url: 'file.php',
type: "POST",
data: formData,
async: false,
success: function (msg) {
alert(msg);
},
error: function(msg) {
alert('Ошибка!');
},
cache: false,
contentType: false,
processData: false
});
e.preventDefault();
});
</script>
<?php
$uploaddir = $_SERVER['DOCUMENT_ROOT'].DIRECTORY_SEPARATOR.'uploads'.DIRECTORY_SEPARATOR;
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$out = "Файл корректен и был успешно загружен.\n";
} else {
$out = "Возможная атака с помощью файловой загрузки!\n";
}
echo $out;
?>
Answer the question
In order to leave comments, you need to log in
The Qt SDK does not have classes for creating an HTTP server, you will have to write your own implementation based on QTcpServer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question