Professional Web Applications Themes

Can someone help me please.... - PHP Development

Hello, The following code grabs the url of a file location on the net from a db on my server for a file download. // connection to grab url of the file mysql_select_db($database_local, $local); $query_dllink = sprintf("SELECT dllink FROM software WHERE swid = %s",$colname_dllink); $dllink = mysql_query($query_dllink, $local) or die(mysql_error()); $row_dllink = mysql_fetch_assoc($dllink); $totalRows_dllink = mysql_num_rows($dllink); ?> So I've gone and grabbed the location. I then stick this following bit in between the header sections on my html page, note I am trying to kick of the download. <? echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"6; URL=http://\"$row_dllink\" \">"; ?> This all work on ...

  1. #1

    Default Can someone help me please....

    Hello,

    The following code grabs the url of a file location on the net from a db
    on my server for a file download.


    // connection to grab url of the file
    mysql_select_db($database_local, $local);
    $query_dllink = sprintf("SELECT dllink FROM software WHERE swid =
    %s",$colname_dllink);
    $dllink = mysql_query($query_dllink, $local) or die(mysql_error());
    $row_dllink = mysql_fetch_assoc($dllink);
    $totalRows_dllink = mysql_num_rows($dllink);
    ?>

    So I've gone and grabbed the location.

    I then stick this following bit in between the header sections on my
    html page, note I am trying to kick of the download.

    <? echo "<META HTTP-EQUIV=\"refresh\" CONTENT=\"6;
    URL=http://\"$row_dllink\" \">"; ?>

    This all work on paper but nothing happens. Basically I want to grab a
    file location url from my db and then start to download that file to the
    user. I am not sure if I am doing this right at all so help would be
    appreciated.

    Any ideas?

    tia.

    td.
    toedipper Guest

  2. #2

    Default Re: Can someone help me please....


    First of all, I have to assume that the file you are downloading i
    local to your web root. If it is not, than this help may not apply.

    The form of the URL, as you call it, should actually be a path to th
    file you want to download in a form similar to

    /web/user/hoohoo/directory/file.ext

    Get the path information from your web host if you don't know it b
    rote.

    I format a link to a download script using a combination of PH
    properties and strings:

    < a href = http://'.$_SERVER['HTTP_HOST']
    '/directory/download.php?id='.$_SERVER['DOENT_ROOT'].'/directory/'.$doc.'">'.$doc.'</a>

    $doc being the name of the file (foo.ext) I want to download.

    To make the file download automatically, you could do something like:

    header('Location: http://'
    $_SERVER['HTTP_HOST'].'/directory/download.php
    title='.$_SERVER['DOENT_ROOT'].'/directory/'.$doc);

    -NOTE: Remember that you can't send header's after sending content t
    the browser, so you should use output buffering (ob_start and ob_end)
    to prevent non-response problems.-

    This will send the path to the file to the download.php script an
    start the download immediately. The download script should loo
    something like the following (it doen't need headers, just th
    following code saved into a file called download.php):

    $title = $_REQUEST['title'];
    if(is_file($title)){
    header("Pragma: public");
    header("Expires: 0"); // set expiration time
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Content-Type: application/force-download");
    header("Content-Type: application/octet-stream");
    header("Content-Type: application/download");
    header("Content-Disposition: attachment
    filename=".basename($title).";");
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($title));

    readfile("$title");
    unlink("$title");
    exit();
    } else {
    print('Unable to Download: '.$title.' as it is not a file.');
    }

    That's about it. All you have to do is modify the URL you are gettin
    from the DB to a path, and you can use p URL to do that (read tha
    PHP manual...there's some really good stuff in their and its absolutel
    free (www.php.net).

    Hope I was of some service.

    =- y knot scrypt -

    --
    pjogre
    -----------------------------------------------------------------------
    pjogren's Profile: http://www.macosx.com/forums/member.php?userid=3932
    View this thread: http://www.macosx.com/forums/showthread.php?t=23136
    macosx.com - The Answer to Mac Support - http://www.macosx.co

    pjogren Guest

  3. #3

    Default Re: Can someone help me please....




    "toedipper" <com> wrote in message
    news:db6pn6$stu$aioe.org... 

    I'm no expert, but.. as I understand it, your script has been triggered by
    some action of the visitor (file selection, whatever), and you are
    presenting a new page to download the (requested) file. If that is indeed
    what you are trying to accomplish, I think you should be using php content
    headers, not a meta refresh tag. In other words, your script will use
    output buffering control to hold the output buffers until you have retrieved
    the file name, checked for file existence, and then, if all is ok, build
    your content-type and content-disposition headers, read the file, and then
    flush the buffer to download the target file.

    George


    George Guest

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
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139