单击服务器上的下载链接后如何删除下载的文件

I am generating a .MSI file and giving a link to download it .but after download I need to delete that file (in case of user selected to 'save' not cancel).please give some inputs to me on this regard.

I thought to use readfile() but it will through output to browser.which is not my case. I need to download the MSI file on click.

<a href="http://localhost/john_CI/june/Enterprise-Setup_test.msi" id='32_bit_url1'>32-bit suite </a> 

make a controller funtion like this :

public function download($id) {
        $this->load->helper('download');
        $filepath = "url/" . $id;
        force_download("file-name", $filepath);
        ignore_user_abort(true);
        unlink($filepath);
    }

better try to do like this.

                header('Content-Description: File Transfer');
                header('Content-Type: application/octet-stream');
                header('Content-Disposition: attachment;  filename='.basename($file));
                header('Expires: 0');
                header('Cache-Control: must-revalidate');
                header('Pragma: public');
                header('Content-Length: ' . filesize($file));
               // Ignore user aborts and allow the script to run                                        
                ignore_user_abort(true);

                //read the contents and store in memory
                readfile($file);

                //remove the file after download
                unlink($file);

I don't know why you want to delete the file just after the download is terminated, anyway if you can would be better to have another approach to this kind of things. Why don't you save the link in a database table and give it an expire date ? This way your user can download the file until the link is active and you can easily delete the expired files later.