Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 12-28-2006, 05:47 AM   #1 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
Downloads

Is there anyway to make php prompt a download to the viewers computer, besides jut redirecting to the zip file?

Such as when you click a download link on a site and it sends you to a page and the download happens while you can view that page?
markster is offline   Reply With Quote
Old 12-28-2006, 06:49 AM   #2 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 673
DJMaze is on a distinguished road
yes, by sending the proper headers and then the data.

PHP Code:
$fp fopen('filename.tgz');
if (
$fp)
{
  
header('Content-Type: application/octet-stream; name="filename.tgz"');
  
header('Content-Length: '.filesize('filename.tgz'));
  
header('Content-Disposition: attachment; filename="filename.tgz"');
  
  
fpassthru($fp);
  
fclose($fp);

__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 12-28-2006, 01:19 PM   #3 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
thank you, you are my savior! what can i do to thank you?
markster is offline   Reply With Quote
Old 12-28-2006, 01:38 PM   #4 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
actually, it didnt work, fopen needs 2 parameters, and none of them seem to work.
markster is offline   Reply With Quote
Old 12-28-2006, 01:40 PM   #5 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
never mind, fopen('file.zip','rb') works
markster is offline   Reply With Quote
Old 12-29-2006, 05:56 AM   #6 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 673
DJMaze is on a distinguished road
Quote:
Originally Posted by markster View Post
never mind, fopen('file.zip','rb') works
Sorry forgot that part. Was just a small wrap.

Quote:
Originally Posted by markster View Post
thank you, you are my savior! what can i do to thank you?
Donate to codenewbie?
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 12-29-2006, 12:41 PM   #7 (permalink)
markster
Code Monkey
 
markster's Avatar
 
Join Date: Jun 2006
Posts: 65
markster is on a distinguished road
I'm kinda skint right now, but that script is the missing piece in my puzzle. the puzzple is an online scripts shop, so when that picks up in business, ill be donating some of the profits to this site!
markster is offline   Reply With Quote
Old 12-29-2006, 05:08 PM   #8 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 673
DJMaze is on a distinguished road
Ofcourse you could always applaud me for the above mentioned post
http://codenewbie.com/forum/reputation.php?p=23355
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Old 01-02-2007, 05:35 AM   #9 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,709
redhead is on a distinguished road
Or searched the php section for download...
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 01-02-2007, 02:56 PM   #10 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 673
DJMaze is on a distinguished road
doh i could have done that as well, would have been a lot less typing
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Making downloads private Redline PHP 2 03-09-2006 04:43 PM
Throttle Downloads on Apache sde Lounge 3 02-29-2004 06:17 PM
Napster sells 5 million downloads redhead Code Newbie News 0 02-26-2004 01:31 AM


All times are GMT -8. The time now is 08:35 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting