Download File on Upload

PHP coding talk.

Moderator: Moderators

Download File on Upload

Postby roders22 on Tue Aug 15, 2006 12:57 pm

Hi all,
I am currently building a little system that allow users to get data from a database and send it for to text file which work. The second step i need now is when the page redirects this download the text file automatically. Can anybody help me with this please.


There must be somebody, who knows how to download a text file from the server as it is?
User avatar
roders22
Registered User
Registered User
 
Posts: 141
Joined: Thu Jun 09, 2005 4:33 pm
Location: Mauritius

Postby iyeru42 on Sun Jan 14, 2007 7:34 pm

http://us3.php.net/manual/en/function.m ... d-file.php

Try that, and see if you can get PHP to move your uploaded file to your disk drive.
User avatar
iyeru42
Registered User
Registered User
 
Posts: 22
Joined: Sun Jan 14, 2007 5:20 pm
Location: Wisconsin, Madison

Postby DoubleJ on Mon Jan 15, 2007 8:53 pm

Try this:
Code: Select all
<?php
// INITIALISE
//
// Now define the type of file and the way to get it to your browser:
header("Content-Type: text; name=\"file.txt\""); // define the filetype.
header("Content-disposition: attachment; filename=file.txt"); // force browser to download the .txt file, rather then showing it in the browser.
//
// File you text file with content
?>

the header statement(second) forces your browser to download the file.
It never hurts to help.....
[ My phpBB Mods and Styles ]
My Mod: [ Simple Shoutbox Mod ]
[ DoubleJWeb ] [ Get Opera ]
User avatar
DoubleJ
Moderator
Moderator
 
Posts: 716
Joined: Sat Jan 22, 2005 9:58 pm
Location: DoubleJWeb.Net

Postby DoubleJ on Mon Jan 15, 2007 8:55 pm

[quote user="iyeru42" post="86684"]http://us3.php.net/manual/en/function.move-uploaded-file.php

Try that, and see if you can get PHP to move your uploaded file to your disk drive.[/quote]
This function is ment to move an uploaded file to the desired location on your host, for example store an uploaded file which was submitted by a form.
You can additionally use it to see if the uploaded file actually was uploaded and does exist.
It never hurts to help.....
[ My phpBB Mods and Styles ]
My Mod: [ Simple Shoutbox Mod ]
[ DoubleJWeb ] [ Get Opera ]
User avatar
DoubleJ
Moderator
Moderator
 
Posts: 716
Joined: Sat Jan 22, 2005 9:58 pm
Location: DoubleJWeb.Net

Headers

Postby iyeru42 on Mon Jan 15, 2007 9:51 pm

But DoubleJ, if he has used <HEAD> tags anywhere in his skinning system BEFORE this function/file, then the "Fatal Error: Headers have already been sent by index.php on line ##" Will occur. I'm not referencing to phpBB skinning, I mean the site he uses, IE: index.htm or whatever his wrapper is.
User avatar
iyeru42
Registered User
Registered User
 
Posts: 22
Joined: Sun Jan 14, 2007 5:20 pm
Location: Wisconsin, Madison

Re: Headers

Postby DoubleJ on Wed Jan 17, 2007 7:16 pm

[quote user="iyeru42" post="86733"]But DoubleJ, if he has used <HEAD> tags anywhere in his skinning system BEFORE this function/file, then the "Fatal Error: Headers have already been sent by index.php on line ##" Will occur. I'm not referencing to phpBB skinning, I mean the site he uses, IE: index.htm or whatever his wrapper is.[/quote]
Even then, the function you mentioned will not download or upload anything to your own computer.
In order to force a download of a .txt file rather then displaying it in the browser, you need to send a header.
Do note that <head> is not the only thing, if you echo anycontent at all, this also includes errors, then headers will fail as that is also content send to the browser.

In order to force a download you need to let the browser know it is a download and this is done with the header() function.
And reading the question, you are being redirected to this .txt file or the page which generates the .txt file so header() function is appropriate here.
It never hurts to help.....
[ My phpBB Mods and Styles ]
My Mod: [ Simple Shoutbox Mod ]
[ DoubleJWeb ] [ Get Opera ]
User avatar
DoubleJ
Moderator
Moderator
 
Posts: 716
Joined: Sat Jan 22, 2005 9:58 pm
Location: DoubleJWeb.Net


Return to PHP Programming

Who is online

Users browsing this forum: No registered users and 4 guests

cron