Jump to content

header() function related question.


dhillarun

Recommended Posts

Hi ,

I am using the following script to enable download.

How to track whether "cancel" button clicked and download is not complete?

Pl do reply me.

 

function download($inline = false)

    {

                $user_agent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ?

                                                $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT;

                     

                while (@ob_end_clean());

 

                $fsize = filesize($this->path.$this->name);

                $mod_date = date('r', filemtime( $this->path.$this->name ) );

 

                $cont_dis = $inline ? 'inline' : 'attachment';

 

        header("Pragma: public");

        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");

        header("Expires: 0");

 

        header("Content-Transfer-Encoding: binary");

                header('Content-Disposition:' . $cont_dis .';'

                        . ' filename="' . $this->name . '";'

                        . ' modification-date="' . $mod_date . '";'

                        . ' size=' . $fsize .';'

                        ); //RFC2183

        header("Content-Type: "    . $this->mime );                    // MIME type

        header("Content-Length: "  . $fsize);

 

                // No encoding - we aren't using compression... (RFC1945)

                //header("Content-Encoding: none");

                //header("Vary: none");

 

        $this->request  =  date("Y-m-d H:i:s", time("Y-m-d g:i:s"));

        $this->status  =  $this->readfile_chunked($this->path.$this->name);

        $this->response =  date("Y-m-d H:i:s", time("Y-m-d g:i:s"));

}

 

function readfile_chunked($filename,$retbytes=true)

    {

        $chunksize = 1*(1024*1024); // how many bytes per chunk

        $buffer = '';

        $cnt =0;

        $handle = fopen($filename, 'rb');

        if ($handle === false)

        {

                return false;

        }

        while (!feof($handle))

        {

                $buffer = fread($handle, $chunksize);

                echo $buffer;

                //sleep(100);

                if ($retbytes)

                {

                        $cnt += strlen($buffer);

                }

        }

        $this->dsize=$cnt;

        $status = fclose($handle);

        if ($retbytes && $status)

        {

                return $cnt; // return num. bytes delivered like readfile() does.

        }

        return $status;

    }

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.