Link to home
Start Free TrialLog in
Avatar of sam15
sam15

asked on

Appl_FileDownlload.


I have a web application (oracle), I have a webpage with "Download" button that generates/downloads a file to the user.

I generate the file on a directory and gets downloaded by another apached web server.

so the download button uses a redirection so that file gets downloaded.

Problem is hat I want to download the file but keep the original application webpage (different webserver/port) so that user continue working with application.

is there a way to do this (i.e download file from filesystem without redirection).

would i be able to do a 2nd redirection back to the orignal webpage after user downloads file.

ASKER CERTIFIED SOLUTION
Avatar of crazedsanity
crazedsanity
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of sam15
sam15

ASKER

Can you show a small example of what you mean.

let us say you have

www.abc.com:7777/webpage1

it has an HTML button to dwonload file at the bottom.

When user hits it, my code generates the file and then does a redirection to
www.abc.com/mydocument (different web server).

But this is only a file and i want user to stay on first web server where application is.
When the user goes to that other page (www.abc.com/mydocument), you can set headers so the browser will just download it (like a link on a website that points to a *.zip file).  Setting a header like "Content-Type: application/force-download" will force the browser to download the file, regardless of what type it actually is.
Avatar of sam15

ASKER

yes, i can set headers in the code.
So are you suggesting if i add "content type" before the redirection link, it would download the file and stay at same page.

or are you suggesting to remove redirection and call the file somehow.

Can you demo with small HTML example.
The destination code, at "www.abc.com/mydocument", would set a header of "content-type: application/force-download"

Here's a PHP example of the destination document:

<?php

// Set a content-type so the browser is forced to download it
header("Content-Type: application/force-download"); 

// get the bits of the URL...
$urlBits = parse_url($_SERVER['REQUEST_URI']);

// --- This is a mythical function that returns the contents that would normally be written out to a file on the filesystem...
echo(get_document_contents($urlBits['path']));

Open in new window

Avatar of sam15

ASKER

There is no destination code at www.abc.com/mydocument. This is just a plain ZIP file.

IDo you mean I just set the content type in the source code that calls that link?

I think also you are not doing a rediretion. You are grabbing the  contents of the target file in the main code that calls it (www.abc.com/mypage). correct?
No, incorrect.  We're definitely not talking about the same thing... start over.

Why doesn't the "Download" button just point directly to the plain ZIP file?
Avatar of sam15

ASKER

because if the download button does some processing (i.e geenrate the file first) before it redirects to the link that downloads it.

Kind of strange though. I made the "download Button" a button type (type="button') with OnClick javascript handler that calls the download  routine. What i see now when you click on it, it will open a small window and then will prompt you if you want to dwonload the file or open it. After it downloads the user stays on the same original page for navigation.
That sounds like an adequate solution.

What does the javascript look like?
Avatar of sam15

ASKER

<input name="button" type="button" class="ButtonStyle"  value="Download Orders"
   onClick=OrdersWin=window.open("download_orders?p_seqno=81","OrdersWin","toolbar=no,scrollbars=yes,status=yes,menubar=yes,location=yes,resizable=yes,width=700,height=400");  >
That looks like it would work... why not just make it a link to "download_orders?p_seqno=81"?