How to auto delete a zip file after using stream_get_contents(); to view a file in php?
<p>I have this code to read a file for preview, but the downside is I have to download the file first from cloud and read from it, but it's a waste of space so I want to delete it after viewing a certain file. Is there an automatic way of doing this? Or do I have to integrate it to a close button?</p>

<pre><code>// Get the container we want to use
$container = $conn-&gt;get_container('mailtemplate');
//$filename = 'template1.zip';
// upload file to Rackspace
$object = $container-&gt;get_object($filename);
//var_dump($object);
//echo '&lt;pre&gt;' . print_r($object,true) . '&lt;/pre&gt;';
$localfile = $dir.$filename;
//echo $localfile;
$object-&gt;save_to_filename($localfile);
    if($_GET['preview'] == "true")
    {
        $dir = "../mailtemplates/";
        $file1 = $_GET['tfilename'];
        $file = $dir.$file1;
        $file2 = "index.html";
        $info = pathinfo($file);
        $file_name =  basename($file,'.'.$info['extension']);
        $path = $file_name.'/'.$file2;
        $zip = new ZipArchive();
        $zip-&gt;open($file);
        $fp = $zip-&gt;getStream($path);
        if(!$fp)
        {
            exit("faileds\n");
            $zip-&gt;close();
            unlink($dir.$filename);                 
        }
        else
        {                           
            $stuff = stream_get_contents($fp);
            echo $stuff;
            $zip-&gt;close();                      
            if($stuff != null)
            {
                unlink($dir.$filename);
            }                       
        }
    }
    else
    {
        unlink($dir.$filename);
    }
</code></pre>
