how to find the file is downloaded in php program

Discussion in 'PHP' started by yasodha, Dec 2, 2007.

  1. #1
    In my php program, when user clicks the download link, image(jpg) file will be downloaded.
    But i need to added a record to the database after download has completed.
    ie., I need to less Credit Points of that particular user after download has completed.
    How do i know by the php program whether download is completed. How can i check this?
    kindly reply for this.

    Thankyou,
    yasodha.
     
    yasodha, Dec 2, 2007 IP
  2. krampus

    krampus Active Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    88
    #2
    I'am not sure what exactly do you need... because I know that there is a way to add a record to database when someone click to download something...

    For example... there sholud be a link on a page..

    <a href='page.php?download=34'>download it</a>

    where 34 should be ID of that picture or something you want to download. And on the "page.php" you do enter in data base record that someone (or that registered user) downloaded file with ID 34 ...

    But I'am not sure that PHP can give you information WHEN someting is DOWNLOADED...
     
    krampus, Dec 2, 2007 IP
  3. Barti1987

    Barti1987 Well-Known Member

    Messages:
    2,703
    Likes Received:
    115
    Best Answers:
    0
    Trophy Points:
    185
    #3
    How are you outputting the file?

    I usually do it in chunks of X bytes, after the loop you add the query to update download complete.

    fopen file
    while_read_file {
    echo binary
    }
    update database

    Peace,
     
    Barti1987, Dec 2, 2007 IP
  4. yasodha

    yasodha Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    yes, i have done this.

    i have given update query in download.php.

    When i click download link, a dialog box appears, whether to Open, Save or Cancel.

    When i give Cancel also the database is updated.

    If i click Cancel database should not update. i have tried this code in many other places in the same program, but no use.

    here is the code i have given.....

    if ($file) {
    while(!feof($file)) {
    print(fread($file, 1024*8));
    flush();
    if (connection_status()!=0) {
    @fclose($file);
    die();
    }
    }
    $uname=$_SESSION['uname'];
    $query="select * from user_det where UserName='$uname' ";
    $qry_result = mysql_query($query) or die(mysql_error());
    if (($row=mysql_fetch_array($qry_result))>0)
    {
    $cp=$row[CrPoints]-1;
    $query="update user_det set CrPoints='$cp' where UserName='$uname'";
    $qry_result = mysql_query($query) or die(mysql_error());
    }
    }
     
    yasodha, Dec 3, 2007 IP