Skip to content

x-sendfile-temporary not working? #33

@morrow95

Description

@morrow95

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions