Upload multiple files to a single HTTP request

How can I upload multiple files in one HTTP request? what I mean, for example, when you have several attachments and you select what you want to download, and then click "download" so that they automatically download, and you do not need to click on them manually.

I use PHP as ssripting for servers.

+4
source share
7 answers

You can send a multipart response in HTTP :

In general, HTTP does not process a multi-part message body like any other type of medium: strictly as a payload. [...] an HTTP user agent MUST follow the same or similar behavior as a MIME user agent when receiving a multi-page type.

[...] If an application receives an unrecognized multiple subtype, the application SHOULD treat it as the equivalent of "multipart / mixed".

But since Firefox is the only browser that I know supports such multiple responses (besides multipart / byterange), you should use the archive file format for this purpose.

+12
source

This is virtually unavailable due to poor browser support. You can pack them into a tar or zip file from the server side and maintain the archive file.

+7
source

I think this is not possible, since each HTTP request has only one URI.

+4
source

You can attach the file using PHP, serveride and request the file or return it from the script by setting the appropriate headers, see the ZipArchive class

Or you create a special client that can analyze your automatically determined message format (flash-application, plug-in), but if your client is just your browser, you will get one answer with a fixed length of content from the server.

+2
source

I don’t know about one HTTP request, but if you want all of them at once, you can scroll through them, changing the header('Location:') for each of them when redirecting the script to load immediately. Although, it would be superfluous and ugly; I think the best way would be to zip them all up, there are instructions on how to do this in the PHP Documentation .

0
source

I use several invisible frames to run multiple downloads at once. There will be more than one HTTP request, but the effect will be what you described.

 <iframe style="display: none;" src="file1.zip"></iframe> <iframe style="display: none;" src="file2.zip"></iframe> <iframe style="display: none;" src="file3.zip"></iframe> 

Most browsers will ask the user if they want to allow multiple downloads (this will prevent the website from sending the file to the file system). In addition, you must ensure that the file is actually loaded, and not just displayed inside an invisible iframe (for example, using header('Content-disposition: attachment'); inside the PHP script serving the file).

In my solution, I use JavaScript to change src after downloading each file, so the files are downloaded sequentially, and my server needs to process fewer requests at the same time. But this solution requires AJAX and is much more complicated.

0
source

Perhaps you can use JS to open multiple popups, each of which loads a download URL. I hope this is the only way.

-2
source

Source: https://habr.com/ru/post/1302339/


All Articles