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
https://forums.phpfreaks.com/topic/41401-header-function-related-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.