PHP If user download file fully?

Posted on 2007-07-24
Last Modified: 2013-12-12
User begins to get a file :
1) can get as by one stream so by the unlimited amount of streams
2) User can continue download the file and script gives him a file by bytes ( or kb ), well and able to give pieces ( for streams ) !  

it is needed to define is a file got fully ONCE ? after download it to forbid getting of this file another time....

My algorithm: to add up the given amount of information for user from all of streams and write to DB ! In the end to check with files this sum ... well and to draw a conclusion to forbid or not ! Here are a few nuances, how to know user pressed STOP ? Maybe did user come to renew download ? Or anew to rock a file ?
Question by:noviceexpert
    LVL 4

    Accepted Solution

    Here is some information i found on this matter, i persoanally do not know how you do it but i hope this can help in some way

    $filename = "the name of my file";
    $filePath = "/path/to/download/$filename";
    //lets read this file to the user
    //open the file for binary reading
    $file = fopen($filePath,"rb");
    // we build some headers
    header("Content-type: application/octet-stream");
    header("Content-Disposition: inline; filename=\"$filename\"");
    header("Content-length: ".(string)(filesize($filePath)));
    while(!feof($file) )// if we haven't got to the End Of file
    print(fread($file, 1024*8) );//read 8k from the file and send to the user
    flush();//force the previous line to send its info
    if (connection_status()!=0)//check the connection, if it has ended...
    fclose($file);//close the file
    die();//kill the script
    fclose($file);//close the file
    //if we get this far, the file was completely downloaded
    //update the database

    Author Comment

    This script will download only in 1 thread and watch if the full file send to user! I want create a script wich can watch the full send to user with unlimited threads and user can continue download if it crashed.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

          Install BugTracker on Windows 2008 server Step 1:  Install windows 2008 server 32 bit OS and configure IIS. Step 2:  Install SQL server ( SQL server 2005 or SQL server 2005 Express edition. The installer for 2008  version isn’t very f…
    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…
    Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now