mod_xsendfile icon indicating copy to clipboard operation
mod_xsendfile copied to clipboard

x-sendfile-temporary not working?

Open morrow95 opened this issue 11 years ago • 3 comments

I am using the beta version because I want to make use of the delete file after download header.

I'll note that the script is working fine and downloads work fine... it is the file delete after download which isn't.

According to the docs you need to set a flag on the file path to allow deletes. Here is my current setup :

Virtual hosts I added :

XSendFilePath /home/test/user-data/ AllowFileDelete

php script :

     function user_download($file_name, $file_ts)
    {

        $path_parts = pathinfo($file_name);
        $file_name  = $path_parts['basename'];
        $file_ext   = $path_parts['extension'];

        $file_path  = $_SERVER['DOCUMENT_ROOT'].'/../user-data/'.$_SESSION['user']['account_id'].'/downloads/'.$file_name;

        // make sure the file exists
        if (is_file($file_path))
        {

            //get current ts
            $now = time();

            // set the headers and prevent caching
            header('X-Sendfile-Temporary: '.$file_path.'');
            header('Pragma: public');
            header('Expires: -1');
            header('Cache-Control: public, must-revalidate, post-check=0, pre-check=0');
            header('Content-Disposition: attachment; filename="'.($file_ts ? $now.'_' : '').$file_name.'"');
            header('Content-Length: '.filesize($file_path).'');

            // set the mime type based on extension
            $ctype_default = 'application/octet-stream';

            $content_types = array(
                'exe' => 'application/octet-stream',
                'zip' => 'application/zip'
            );

            $ctype = isset($content_types[$file_ext]) ? $content_types[$file_ext] : $ctype_default;
            header('Content-Type: '.$ctype.'');

            return true;
        }   
    }

I am wondering if it matters that my filepath is not exact... meaning in this download the file path would have been /home/test/user-data/user1/downloads/text.zip... not exactly in the user-data folder which was set in virtual hosts and given the delete tag?

A side question to go along with this... can I use a wildcard in my file path like XSendFilePath /home/test/user-data/*/downloads/ AllowFileDelete which would handle the 'downloads' folder for each user (every user has their own specific download folder location).

morrow95 avatar Oct 12 '14 05:10 morrow95

Anyone else have this issue or have any ideas?

morrow95 avatar Oct 20 '14 06:10 morrow95

Still wiuld like a response for this :)

morrow95 avatar Oct 10 '15 18:10 morrow95

Same problem here! The "X-Sendfile-Temporary" header doesn't seem to work despite putting the "AllowFileDelete" flag.

pitininja avatar Jun 27 '17 15:06 pitininja