PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old October 22nd, 2004, 03:12 PM
Dhruv Dhruv is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 3 Dhruv User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Content disposition

Hi

I've been trying to understand how to force a user to download a file. What i've done is save a bunch of rows from the DB into a variable called $data.

From here, I tried to study how the header actually works.

http://uk2.php.net/manual/en/function.header.php

I'm adding these lines to the function.. so basically my function is now

PHP Code:
function XYX()
{
 
$data "some large data string..";
 
header("Content-Type: text/x-delimtext; name=\"filename.sql\"");
header("Content-disposition: attachment; filename=filename.sql");
 
echo 
$data;


But the browser doesnt seem to force the user to download it. I dont understand what it is that i'm doing wrong. Could someone please help?

cheers!

Reply With Quote
  #2  
Old October 23rd, 2004, 06:49 AM
kode_monkey kode_monkey is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Posts: 367 kode_monkey User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 21 sec
Reputation Power: 6
What do you mean by 'force them to download it'? Do you want it to open the usual download options dialog when the page opens or just start downloading without consulting the user?

-KM-

Reply With Quote
  #3  
Old October 23rd, 2004, 08:40 AM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
http://us2.php.net/manual/en/function.header.php

Essentially, your header will look something like the following:
Code:
             header("Content-disposition: attachment; filename=/real/path/to/filename.sql");
             header('Expires: Mon, 26 Nov 1962 00:00:00 GMT');
             header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
             header('Pragma: no-cache');

or for IE :
Code:
 
             header("Content-disposition: attachment; filename=/real/path/to/filename.sql");
             header('Expires: Mon, 26 Nov 1962 00:00:00 GMT');
             header("Last-Modified: " . gmdate("D,d M Y H:i:s") . " GMT");
             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
             header('Pragma: public');
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #4  
Old January 14th, 2005, 07:44 AM
Raya Raya is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Sofia, Bulgaria
Posts: 2 Raya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Raya
Smile What is the effect of this header ?

Is the source you wrote laidbak have the effect of opening a "download window" and is this work for opening a file for download from FTP server?


Thanks, R.

Reply With Quote
  #5  
Old January 14th, 2005, 01:50 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
Quote:
Is the source you wrote laidbak have the effect of opening a "download window"
Yes, this will effectively force the browser to see this file as a stream of input and download it as a file.

This is commonly used to serve a files that you would like to keep out of your document root.

Quote:
and is this work for opening a file for download from FTP server?
If you are serving an ftp file, you do not need to protect the file by wrapping it in a routine such as this. You could simply provide an ftp link right to the file.

If the ftp has password protection, and you are not willing to give up the username/password combo, then this is probably not the correct approach.

Reply With Quote
  #6  
Old January 17th, 2005, 06:22 AM
Raya Raya is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Location: Sofia, Bulgaria
Posts: 2 Raya User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Send a message via ICQ to Raya
Well yes the FTP server has username and password but I pass them like this :

ftp://username:_password@ftp/some_folder/some_file.mp3

it this OK ?



thanks

Reply With Quote
  #7  
Old January 17th, 2005, 03:11 PM
digitallysmooth digitallysmooth is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Posts: 788 digitallysmooth User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 34 m 21 sec
Reputation Power: 7
This is fine if you don't care that you are sharing your username/password with whomever.

Reply With Quote
  #8  
Old January 18th, 2005, 05:18 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by laidbak
This is fine if you don't care that you are sharing your username/password with whomever.

FTP is insecure anyway, sending the username/password in plain text, it wouldn't be hard for some packet sniffer or whatever to grab the passwords.
__________________
http://www.phptutorials.cjb.net. go on, give it a click!

Reply With Quote
  #9  
Old January 18th, 2005, 09:01 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
It's still much easier to get the username/password when its BLATANLY DISPLAYED IN THE URL... =)

Reply With Quote
  #10  
Old January 18th, 2005, 09:30 AM
mattp23 mattp23 is offline
Moderated
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: UK
Posts: 82 mattp23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 43 m 44 sec
Reputation Power: 6
Quote:
Originally Posted by MadCowDzz
It's still much easier to get the username/password when its BLATANLY DISPLAYED IN THE URL... =)

Is true but there are many people who seem to think that protocols like FTP, POP, IMAP etc are secure!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > Content disposition


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT