Closed Thread Icon

Topic awaiting preservation: Presenting a file for download without creating the file? (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=26366" title="Pages that link to Topic awaiting preservation: Presenting a file for download without creating the file? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Presenting a file for download without creating the file? <span class="small">(Page 1 of 1)</span>\

 
H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-02-2005 02:20

Anyone know if its possble to I guess have a chunk of text, and present this as a file to download - without actually creating the file on the server.

Thanks

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 08-02-2005 11:44

Ya got me there. If I understand what you're saying, I imagine that it might not be possible. What you're basically trying to do is download a dynamically created file directly to the user's system, right? Even if it is possible, sounds like a very abusable thing to do. How does the user know you're not going to dynamically create a self-executing virus? It's hard enough to trust downloads as it is.

Or maybe I'm just being paranoid. Or maybe I don't understand what you're trying to do.

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-02-2005 12:29

Ah ok, all it is is for my website statistics. I show the graphs and all that and want to offer them the ability to download the csv file.

I have the code and everything done already, and can put all the text into a file. I guess the question is if its possible to offer the csv data for download (they still have to press "Accept") the same way as when you offer file in headers etc. I mean i can just create the file, let them download then delete it - but if i can do it this way it saves that step.

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 08-02-2005 15:01

Hmmm... OK, I've never tried anything like this, but I'm wondering if the answer isn't something simple. For example, could you create a link to the csv file and then just have people save that using the context menu (i.e., right-click for PC users)? I don't see why that wouldn't work, as you long as you can provide a link to the dynamic content.

Basically, if you can send the info to the client, then it is downloadable by default.

Or am I overlooking something?

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 08-02-2005 16:29

He's looking to offer the csv file without actually having the csv file on the server - grab the data, create the file, but save it only on the client machine and not on the server.

Unfortunately I have no knowledge of what would be involved, so can't help.

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-02-2005 17:10

No worries, thanks all - its easy enough to do it the other, just makes more interesting to look at doing something special! :P

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 08-02-2005 17:57

Yes it is definitely possible to send text to the client without first creating it as a file on the server. I assume you are creating the data using a server side program in Perl or PHP.

I have done this several times in Perl. The easiest way to do it with Perl is to use the CGI module. I assume there is a similar module in PHP.

You can, of course, do this from any server side program (Perl, C, C++, Shell script, PHP, etc.) by first generating the headers and sending them to standard out and then sending your (formatted or unformatted) text to standard out. The server will take this output from the program and send it to the client.

People tend to run into problems when they mistakes in the headers. The server creates no output for that. I think you can check your error logs to find out what the problem is. Once you get the header right, the rest is easy.

.



-- not necessarily stoned... just beautiful.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 08-02-2005 22:57

Here's the skinny:

You have a regular php file, which happens to output whatever you want to save.
Additionally, it set's some header() directives which tell the browser that this is a) a file to store. Don't display, just offer the save as dialog and b) the suggested filename.

Now, you'll probably find the headers at php->header() - it's something containing the word 'attachment'...

ah, found it (sligthly commented by me)

code:
<?php
// We'll be outputting a PDF
header('Content-type: application/pdf'); 
//application/octet-stream would be good if you have more or less unspecified data, and don't want the browser to handle it 

// It will be called downloaded.pdf
header('Content-Disposition: attachment; filename="downloaded.pdf"');

// The PDF source is in original.pdf - or print whatever you want.
readfile('original.pdf');
?>



so long,

->Tyberius Prime

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-03-2005 02:03

Ah thanks for that, im pretty silly i should have looked at the code i did recently for a normal file download module which does a simliar thing, perhaps instead of reading the file I can just use my text!! Will give it a go and let you know how it turns out.

Thanks

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 08-03-2005 03:37

Ah... I get it now. Hope everything works out.

And in passing... TP: when did you start saying things like "the skinny"?

___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 08-03-2005 09:12

uh... I have no idea. Think the Doc taught me that particular colloquial phrase.
Or was it my host mother?

Who knows what strange pieces of information float around in my head.
Is it a phrase that's moved on to be 'not cool' ;-)?

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 08-03-2005 09:41

Heh i didn't really notice till it was pointed out - to be honest i dont think i've seen it used anywhere before :P

I don't think it would be considered 'not cool' , maybe just entice people into getting confused as to what it really means =/

« BackwardsOnwards »

Show Forum Drop Down Menu