Automatic file transfer from HTML

I am creating a web application that guides my users through setting up and installing the application. It dynamically creates a set of configuration files and then sends them to an archive (.ZIP file) along with the installer for the application. The webpage is generated from a linux shell script (sorry), and for security reasons, I would prefer that the file be sent directly from the script rather than as a link, so the user cannot access it directly.

Here's the process: after the user has entered some information and the files have been generated, I want to display a page with instructions and then start downloading automatically without asking the user to click on the download this file link

#!/bin/bash
echo_header_and_instructions         # Standard HTML
<Magic HTML tag to start transfer>   # ??? What goes here???
command_to_stream_the_files          # Probably 'cat'
echo_end_tags                        # End the page.

      

Thank you for your help!

0


source to share


3 answers


A friend provided the magic: use a tag <iframe>

to create an "invisible" frame that only contains the file to upload:



<iframe id="file_download" width="0" height="0" scrolling="no" 
   frameborder="0" src=/cgi-bin/my/scripts/sendfiles?file=$filename.zip>
   You need a browser that supports frames.
</iframe>`

      

0


source


You cannot do what I think. You can force the file upload through the following headers, but as far as I know you cannot mix HTML and file uploads.

Headers:

Content-type: MIME / type
Content-Disposition: attachment; filename = "archive.zip"
Content-Length: filesize_in_bytes


The length of the content is optional, but use it to make sure the upload dialog can show how much more file to upload.

The thing you can do is reload the page with javascript. Since the page is a file upload, the original HTML page will remain in place:

<html>
<head>
<title> This is the page containing information </title>
<script type = "text / javascript">
window.onload = function () {
 document.location = 'somefile.zip';
}
</script>
</head>
<body>
This page will stay visible while the file is being downloaded <br>
</body>
</html>
+3


source


I think you can force the browser to prompt the user to download the file using the meta tag to do the update, but as Pim Yager said I don't think you can do it with a single pass. You could try doing something like:

<meta http-equiv="refresh" content="5;url=http://example.com/pathtodownload.zip" />

      

+1


source







All Articles