SitePoint Sponsor

User Tag List

Page 3 of 3 FirstFirst 123
Results 51 to 61 of 61
  1. #51
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    They may be using a redirect (meta tag) to redirect to the download script.

  2. #52
    SitePoint Member
    Join Date
    Nov 2008
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can create a page that says something like "your download will begin shortly. If your download doesn't start click here" (include a link to the script) and then refresh the page by pointing it to the script and passing the download params. You can refresh using the following methods:

    A meta-tag

    Code:
    <META HTTP-EQUIV="Refresh" CONTENT="10;URL=/cgi-bin/download.cgi?ID=file.jpg">
    Javascript

    Code:
    <SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript">
    <!--
    function redirect () { setTimeout("go_now()",5000); }
    function go_now ()   { window.location.href = "/cgi-bin/download.cgi?ID=file.jpg"; }
    //-->
    </SCRIPT>
    I, personally, like to include both.

  3. #53
    SitePoint Member
    Join Date
    Apr 2008
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On my system, I needed to add:
    binmode DLFILE;
    immediately after:
    open(DLFILE, "$files_location/$ID")...

    otherwise files were not downloaded in their entirety... bytes were dropped and the downloaded files didn't open correctly.

  4. #54
    mrgtb
    SitePoint Community Guest
    is there anyway to add a download counter that will get displayed against each download

  5. #55
    yks
    SitePoint Community Guest
    I try to download *.doc file. I get only first 590 bytes, I tried
    ...
    print "Content-Type:application/x-download\n";
    print "Content-Length: 10000 \n"
    ...

    didnot help, "binmode DLFILE" too

  6. #56
    Alex
    SitePoint Community Guest
    No, the entire script don't work,
    i can only get an error-message "The server can't open the file: No such file or directory"

  7. #57
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Alex View Post
    No, the entire script don't work,
    i can only get an error-message "The server can't open the file: No such file or directory"
    The script works, you just don't know how to get it to work yet. Have you ever installed a perl script on your server before?

  8. #58
    SitePoint Member
    Join Date
    Jul 2009
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I must be missing something because every time I try running this all I get is the print messages on my page, and the file which I'm trying to download (small text file) simply displaying fully on my page. Where is the save as box?

  9. #59
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The save-as box should be initiated from these lines in the file:

    print "Content-Type:application/x-download\n";
    print "Content-Disposition:attachment;filename=$ID\n\n";

    If they are not, have you changed anything in the script?

  10. #60
    SitePoint Wizard bronze trophy KevinR's Avatar
    Join Date
    Nov 2004
    Location
    Moon Base Alpha
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a more robust article and code discussing the same topic here:

    http://bytes.com/topic/perl/insights...ad-script-perl

  11. #61
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cannot seem to get the script to work, yet I copied it very carefully and have re-checked it several times. I get the following error:

    Software error:

    syntax error at download.cgi line 23, near ")

    print"
    Execution of download.cgi aborted due to compilation errors.

    What have I done incorrectly... following is my final script:
    #!/usr/bin/perl
    use CGI ':standard';
    use CGI::Carp qw(fatalsToBrowser);
    my $files_location;
    my $ID;
    my @fileholder;
    $files_location = "think-lat/public_html/upload";
    $ID = param('ID');
    if ($ID eq '') {
    print "Content-type: text/html\n\n";
    print "You must specify a file to download.";
    } else {
    open(DLFILE, "<$files_location/$ID") || Error('open', 'file');
    @fileholder = <DLFILE>;
    close (DLFILE) || Error ('close', 'file');
    print "Content-Type:application/x-download\n";
    print "Content-Disposition:attachment;filename=$ID\n\n";
    print @fileholder
    } sub Error {
    print "Content-type: text/html\n\n";
    print "The server can't $_[0] the $_[1]: $! \n";
    exit;
    }


Bookmarks

Posting Permissions

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