Web Hosting Talk







View Full Version : Automatically start download dialogue


AC1
08-30-2002, 07:07 AM
Hi

I have seen a few sites which send me an email containing a web page link to receive a free download of an ebook, for example.

I then click on the web page in the email and the ftp dialogue automatically starts and all I have to do is select the location on my PC where I want to save the file.

Does anyone know how this is done?

Cheers
Andy

Steve-PWH
08-30-2002, 07:11 AM
Certain mime types will do that automaticly

like
.gz
.zip
.exe

ETC.

Duey
08-30-2002, 07:11 AM
its done through your operating system its just a default setting nothing to do with PHP

Rich2k
08-30-2002, 08:08 AM
You do this using content-disposition in the header.

e.g. (note this example is for inline download... i.e. the current PHP script echos the file content). You can do a similar thing for a remote file as well

header("Content-Type: application/pdf");
header("Content-Length: " . $length);
header("Content-Disposition: inline; filename=" . $filename);
echo $document;

Ahmad
08-30-2002, 11:52 AM
FTP doesn't have content disposition ;)

AC1
09-01-2002, 04:40 AM
Hi

Does anyone know where I can find an example of how this is done?

Cheers
Andy

:: paVel ::
09-01-2002, 05:26 AM
Originally posted by AC1
Hi

Does anyone know where I can find an example of how this is done?

Cheers
Andy

try... http://www.hotscripts.com

Rich2k
09-01-2002, 06:27 AM
You initiate the download to an FTP source from an http connection. That's how all these downloads sites do it.

The example I gave is for an inline download. What you need is to use content-disposition for a remote file

DavidU
09-01-2002, 11:41 AM
Originally posted by Rich2k
You initiate the download to an FTP source from an http connection. That's how all these downloads sites do it.

The example I gave is for an inline download. What you need is to use content-disposition for a remote file

Rich,

How to do force an FTP transport when you've already initiated an HTTP connection?

header() won't work.

-davidu

dreamrae.com
09-02-2002, 08:35 AM
i would suggest using Rich2k's code spinnet or just being lazy and doing this: header("Location: filepath_here");

DavidU
09-02-2002, 11:32 AM
Originally posted by dreamrae.com
i would suggest using Rich2k's code spinnet or just being lazy and doing this: header("Location: filepath_here");

I want to know how to initiate an FTP connection with PHP from an established HTTP connection.

Rich2k can do it, I just want to know how.

-davidu

mind21_98
09-02-2002, 12:47 PM
Couldn't you force the content type to be "application/octlet-stream"? Every browser I've seen will show the download dialog when that is received.

DavidU
09-02-2002, 01:05 PM
Originally posted by mind21_98
Couldn't you force the content type to be "application/octlet-stream"? Every browser I've seen will show the download dialog when that is received.

Yep. That's a great technique. In fact, the PDF example rick2k gave would most likely result in Acrobat being loaded into the window of the browser depending on the browser settings and if acrobat is installed.

application/octet-stream is one of the few ways I know to force a file::save dialog.

-davidu

Ahmad
09-02-2002, 04:56 PM
As far as I know, there are no MIME types in the FTP specifications. It totally depends on how your operating system is set up. Using HTTP, though, to point to an FTP file and define its MIME types is something new to me.

The Prohacker
09-02-2002, 05:11 PM
For downloading a file off of an FTP:

http://www.php.net/manual/en/function.ftp-get.php


You'll need PHP compiled with ftp support....

DavidU
09-02-2002, 07:13 PM
Originally posted by Ahmad
As far as I know, there are no MIME types in the FTP specifications. It totally depends on how your operating system is set up. Using HTTP, though, to point to an FTP file and define its MIME types is something new to me.

Rick2k knows how to do it and I'm just waiting for him to share...


:D :D :D

-davidu

DavidU
09-02-2002, 07:14 PM
Originally posted by The Prohacker
For downloading a file off of an FTP:

http://www.php.net/manual/en/function.ftp-get.php


You'll need PHP compiled with ftp support....

What we're talking about though is "upload" to the client, or download for them. Not downloading to the server.

-davidu

The Prohacker
09-02-2002, 07:25 PM
Originally posted by DavidU


What we're talking about though is "upload" to the client, or download for them. Not downloading to the server.

-davidu


An easier thing though would be get the file to the server, then feed it to the end user....



Remote FTP Server -> Web Server -> Client...

This would sovle alot of problems with clients, such as firewalls and proxies...

Also, not all browsers have FTP support, so if you feed them to an FTP url, it will come up with errors...

DavidU
09-02-2002, 08:16 PM
Originally posted by The Prohacker



An easier thing though would be get the file to the server, then feed it to the end user....



Remote FTP Server -> Web Server -> Client...

This would sovle alot of problems with clients, such as firewalls and proxies...

Also, not all browsers have FTP support, so if you feed them to an FTP url, it will come up with errors...

What does that have to do with what we're talking about? We're talking about establishing an FTP download after an HTTP connection has already been established.

Feel free to start a new thread on the merits of HTTP vs FTP downloading. k, thx.

-davidu

The Prohacker
09-02-2002, 08:24 PM
Originally posted by DavidU


What does that have to do with what we're talking about? We're talking about establishing an FTP download after an HTTP connection has already been established.

Feel free to start a new thread on the merits of HTTP vs FTP downloading. k, thx.

-davidu


Well considering many users don't know ftp or can't use it, its nice to accomdate them.. Its good programming...

I see this thread started as:
"I then click on the web page in the email and the ftp dialogue automatically starts and all I have to do is select the location on my PC where I want to save the file. "

I see this as a user that wants a link to download a file, my suggest will aid in directing someone in how to make the script...

I really don't see why you want to act so arrogant.. But hey, have fun :D

DavidU
09-02-2002, 09:55 PM
Originally posted by The Prohacker
Well considering many users don't know ftp or can't use it, its nice to accomdate them.. Its good programming...


In most browsers, clicking an FTP link will simply display the File::Save dialog, not launch their FTP application.

Originally posted by The Prohacker
I see this thread started as:
"I then click on the web page in the email and the ftp dialogue automatically starts and all I have to do is select the location on my PC where I want to save the file. "

I see this as a user that wants a link to download a file, my suggest will aid in directing someone in how to make the script...


I disagree, I think the poster just didn't know how to say "File-->Save" and said FTP erroneously. I think the transport protocol was largely irrelevant.

Originally posted by The Prohacker
I really don't see why you want to act so arrogant.. But hey, have fun :D

It's not arrogance. I want to know how Rick2K initiates FTP downloads automatically from an established HTTP connection using PHP. He said he could do it, I don't really know an easy way that isn't a hack and I am curious. Why he isn't sharing it (maybe he has a real life) is unknown. That's all I want to know, clarification on an earlier post. Everything you posted has been right except it had nothing to do with the thread, that's why I suggested starting a new thread on the merits of FTP vs HTTP downloads.

-davidu

AC1
09-03-2002, 05:34 AM
Ok OK,

Put the gloves away, no need to start a fight here.

Thank you for all the posts on this.

I did make an error with my original post.

It is a 'File download' box which appears when I click on the url and not an FTP download. Here is an example: http://www.aaasoftware-ezine.com/ebookguide.zip

Sorry for posting the wrong information in my original post but until it was pointed out I thought they where the same thing.

Next time I will be sure to post an example upfront so I don't create confusion.

Thanks for all your help,

Andy

Rich2k
09-03-2002, 06:21 AM
Woah... who would have thought it could generate an argument.

Sorry I've been away!

You can try something like this:


header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=ftp://domain.com/file.doc");


Then simply call this file something like download.php and stick it on an http server (rather than ftp). Of course your FTP server will have to be anonymous ftp enabled otherwise you will have to go through the much more complicated method of connecting in PHP via FTP and reading the file in yourself.

I have tested this on my own server (PHP 4.2.2 on Apache) and it works fine. It initiates a file download dialog rather than loading Word into the browser

It is also reported to work on Macs too.

DavidU
09-03-2002, 09:39 AM
Originally posted by Rich2k
Woah... who would have thought it could generate an argument.

Sorry I've been away!

You can try something like this:


header("Content-Type: application/msword");
header("Content-Disposition: attachment; filename=ftp://domain.com/file.doc");


Then simply call this file something like download.php and stick it on an http server (rather than ftp). Of course your FTP server will have to be anonymous ftp enabled otherwise you will have to go through the much more complicated method of connecting in PHP via FTP and reading the file in yourself.

I have tested this on my own server (PHP 4.2.2 on Apache) and it works fine. It initiates a file download dialog rather than loading Word into the browser

It is also reported to work on Macs too.


Awesome. I had no idea you could do that.

Thanks Rich2k.



-davidu

Rich2k
09-03-2002, 12:49 PM
Neither did I for a long time. It's actually not very well documented if you run a search on Google. The inline method tends to be mentioned a lot more.

AC1
09-04-2002, 06:28 AM
Thanks to everyone for their help on this.

Andy

silversurfer
11-06-2002, 12:37 AM
Is there a complete script that someone can share with me? thanks

AC1
11-06-2002, 03:24 AM
Hi

Here is the code I ended up using. This is all the code I have in the download screen.

Just change the $files and $filenames to the file name to be downloaded and $url to the directory the file exists in.

<?
$files="servicesellersmasterscourse.zip";
$filenames="servicesellersmasterscourse.zip";
$url= "/www/download/";
$total=$url . $files;
Header ( "Content-Type: application/octet-stream");
Header ( "Content-Length: ".filesize($total));
Header( "Content-Disposition: attachment; filename=$filenames");
readfile($total);
?>

If you want to see it in action go to the site below and click on the 'service sellers masters, free book download' on the left hand side of the screen and you will see how it works.

I hope this helps.

silversurfer
11-06-2002, 03:44 AM
Thanks.
My original script has problem cos of the readfile. Is there any other way? The problem is that my downloads are offsite. (And are huge files or over 100mb) . To do this, it will read to buffer on the php server (and it fails frequently cos of the size of the file) and then send to the downloader. This takes up huge amounts of bandwidth as the file is first transferred from download server to the php server, before sending to the downloader especially for downloads of this size. In actual fact, meaning I use up twice the bandwidth for a download. (a 10mb file will cost me 10mb to transfer to the local server, and another 10mb to send to downloader). Any help is appreciated.

silversurfer
11-06-2002, 04:08 AM
Originally posted by The Prohacker



An easier thing though would be get the file to the server, then feed it to the end user....



Remote FTP Server -> Web Server -> Client...

This would sovle alot of problems with clients, such as firewalls and proxies...

Also, not all browsers have FTP support, so if you feed them to an FTP url, it will come up with errors...

This has tremendous problems for scalability and is not cost effective as you need to pay for twice the bandwidth. When the Remote server transfers to the Web Server and then when the Web server sends to the clients. A really bad way to do this especially if volume is large or if files are huge.

Studio64
11-06-2002, 03:11 PM
:D.. I just want to throw some more wood on the fire...

How about this


<html>
<a href="ftp://site.com/file.zip" target="hide">Click To Start</a>

<i frame=":blank" name="hide" width="0" height="0">
</iframe>

</html>



Oh,... How about this

META REFRESH :D

Umm... I can do it by javascript as well :D...

silversurfer
11-06-2002, 11:31 PM
How about if I want to hide the location of the remote server?

Studio64
11-07-2002, 09:19 AM
Originally posted by silversurfer
How about if I want to hide the location of the remote server?

If you stick w/ a HTTP connection PHP can do a good job of hiding the source of the download because you can emulate the MIME types it passes.

So you can check the $HTTP_REFERER to ensure it came from your site (if you want) then pass the file threw PHP and that would mask the source of the file.

silversurfer
11-07-2002, 09:27 AM
Do you have any ready code? I am a programming idiot :D I know nothing about programming.

Studio64
11-07-2002, 09:35 AM
Originally posted by silversurfer
Do you have any ready code? I am a programming idiot :D I know nothing about programming.

http://wiggie.std64.com

Example in action w/ source