S
S
strager12020-10-22 14:35:39
HTML
strager1, 2020-10-22 14:35:39

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>


Server handler:
<?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;

?>


The whole problem is that there is not and will not be php on the server, therefore, you need to write the handler only using C ++ and Qt. How to do it and can it be done at all?
Another option is to load via JavaScript using the put method, but the example found on the Internet does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ighor July, 2020-12-20
@IGHOR

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 question

Ask a Question

731 491 924 answers to any question