SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Technographs's Avatar
    Join Date
    Jan 2009
    0 Post(s)
    0 Thread(s)

    Question insert into the database after downloading an file


    I am providing the users to download a file. I wants to have user log for downloading the file.

    I want that if an user really download the file then it should enter in the database. Below is the code i am using.

    PHP Code:
    // Quick check to verify that the file exists
    if( !
    file_exists($file) ) die("File not found");
    // Force the download
    header("Content-Disposition: attachment; filename=\"" basename($file) . "\"");
    header("Content-Length: " filesize($file));
    header("Content-Type: application/octet-stream;");
    When an user clicks on an file name , it prompts an download window with as usual two options download and cancel. What i would like to have is that when someone really downloads the file then it should insert in the database.

    Currently when someone clicks on the file it saves in the database instantly insead of actual download.

    Please help.


  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    0 Post(s)
    0 Thread(s)
    There's no solid way to know if they really downloaded it. Some(all?) browsers start downloading before you even make the choice of whether or not to cancel.

    All you can really do is measure how many bytes your script outputs, and compare that to the filesize. Depending on the webserver, and how you have php interface with it, this will probably only tell you how many bytes you gave to the webserver. It doesn't tell you how many bytes the webserver gave to the client, nor how many bytes the client received.

    If you still want to proceed to do this, make sure you turn output buffering off. Then you can output a little at a time with fread(), while using flush() and checking the connection


Posting Permissions

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