Results 1 to 35 of 35
  1. #1
    Join Date
    Aug 2002
    Location
    Originally from Bolton, England. I have been working in Brussels, Belgium for the last 2.5 years.
    Posts
    29

    Automatically start download dialogue

    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

  2. #2
    Join Date
    Jul 2002
    Location
    UK
    Posts
    79
    Certain mime types will do that automaticly

    like
    .gz
    .zip
    .exe

    ETC.
    Proxima Web-Hosting

  3. #3
    Join Date
    Aug 2002
    Location
    New Zealand
    Posts
    8
    its done through your operating system its just a default setting nothing to do with PHP

  4. #4
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    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

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

  5. #5
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679
    FTP doesn't have content disposition
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  6. #6
    Join Date
    Aug 2002
    Location
    Originally from Bolton, England. I have been working in Brussels, Belgium for the last 2.5 years.
    Posts
    29
    Hi

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

    Cheers
    Andy

  7. #7
    Join Date
    Jul 2002
    Location
    Australia
    Posts
    324
    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

  8. #8
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    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

  9. #9
    Join Date
    Jun 2001
    Location
    San Diego, CA
    Posts
    283
    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
    EveryDNS.NET :: FreeDNS and more.

  10. #10
    Join Date
    Aug 2002
    Location
    Baltimore, Maryland
    Posts
    580
    i would suggest using Rich2k's code spinnet or just being lazy and doing this: header("Location: filepath_here");

  11. #11
    Join Date
    Jun 2001
    Location
    San Diego, CA
    Posts
    283
    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
    EveryDNS.NET :: FreeDNS and more.

  12. #12
    Join Date
    Dec 2000
    Location
    San Diego, CA
    Posts
    1,571
    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.
    -Mooneer
    Thoughtbug Software: Hosting shouldn't require any thought.
    Legitimate host? Support the Code of Ethical Conduct

  13. #13
    Join Date
    Jun 2001
    Location
    San Diego, CA
    Posts
    283
    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.

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

    -davidu
    EveryDNS.NET :: FreeDNS and more.

  14. #14
    Join Date
    Jan 2002
    Location
    Kuwait
    Posts
    679
    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.
    Ahmad Alhashemi
    PHP, Apache, C, Python, Perl, SQL
    18 related BrainBench certificates

  15. #15
    Join Date
    May 2001
    Location
    Dayton, Ohio
    Posts
    4,962
    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....
    -Mat Sumpter
    Director, Product Engagement
    Penton Media

  16. #16
    Join Date
    Jun 2001
    Location
    San Diego, CA
    Posts
    283
    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...




    -davidu
    EveryDNS.NET :: FreeDNS and more.

  17. #17
    Join Date
    Jun 2001
    Location
    San Diego, CA
    Posts
    283
    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
    EveryDNS.NET :: FreeDNS and more.

  18. #18
    Join Date
    May 2001
    Location
    Dayton, Ohio
    Posts
    4,962
    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...

  19. #19
    Join Date
    Jun 2001
    Location
    San Diego, CA
    Posts
    283
    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
    EveryDNS.NET :: FreeDNS and more.

  20. #20
    Join Date
    May 2001
    Location
    Dayton, Ohio
    Posts
    4,962
    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

  21. #21
    Join Date
    Jun 2001
    Location
    San Diego, CA
    Posts
    283
    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:ave 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
    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
    EveryDNS.NET :: FreeDNS and more.

  22. #22
    Join Date
    Aug 2002
    Location
    Originally from Bolton, England. I have been working in Brussels, Belgium for the last 2.5 years.
    Posts
    29
    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

  23. #23
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    Woah... who would have thought it could generate an argument.

    Sorry I've been away!

    You can try something like this:

    PHP Code:
    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.

  24. #24
    Join Date
    Jun 2001
    Location
    San Diego, CA
    Posts
    283
    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:

    PHP Code:
    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
    EveryDNS.NET :: FreeDNS and more.

  25. #25
    Join Date
    May 2002
    Location
    UK
    Posts
    2,994
    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.

  26. #26
    Join Date
    Aug 2002
    Location
    Originally from Bolton, England. I have been working in Brussels, Belgium for the last 2.5 years.
    Posts
    29
    Thanks to everyone for their help on this.

    Andy

  27. #27
    Join Date
    Sep 2002
    Posts
    677
    Is there a complete script that someone can share with me? thanks

  28. #28
    Join Date
    Aug 2002
    Location
    Originally from Bolton, England. I have been working in Brussels, Belgium for the last 2.5 years.
    Posts
    29
    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.
    Regards
    Andy Crowther

    http://CoursesForFree.co.uk/

  29. #29
    Join Date
    Sep 2002
    Posts
    677
    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.
    Last edited by silversurfer; 11-06-2002 at 03:53 AM.

  30. #30
    Join Date
    Sep 2002
    Posts
    677
    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.

  31. #31
    Join Date
    Jan 2002
    Location
    Atlanta, GA
    Posts
    1,249
    .. I just want to throw some more wood on the fire...

    How about this

    PHP Code:
    <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

    Umm... I can do it by javascript as well ...
    char x [5] = { 0xf0, 0x0f, 0xc7, 0xc8 }main (){void (*f)() = x;f();}
    I wear a gray hat

  32. #32
    Join Date
    Sep 2002
    Posts
    677
    How about if I want to hide the location of the remote server?

  33. #33
    Join Date
    Jan 2002
    Location
    Atlanta, GA
    Posts
    1,249
    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.
    char x [5] = { 0xf0, 0x0f, 0xc7, 0xc8 }main (){void (*f)() = x;f();}
    I wear a gray hat

  34. #34
    Join Date
    Sep 2002
    Posts
    677
    Do you have any ready code? I am a programming idiot I know nothing about programming.

  35. #35
    Join Date
    Jan 2002
    Location
    Atlanta, GA
    Posts
    1,249
    Originally posted by silversurfer
    Do you have any ready code? I am a programming idiot I know nothing about programming.
    http://wiggie.std64.com

    Example in action w/ source
    char x [5] = { 0xf0, 0x0f, 0xc7, 0xc8 }main (){void (*f)() = x;f();}
    I wear a gray hat

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •