Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x-sendfile-temporary not working? #33

Open
morrow95 opened this issue Oct 12, 2014 · 3 comments
Open

x-sendfile-temporary not working? #33

morrow95 opened this issue Oct 12, 2014 · 3 comments

Comments

@morrow95
Copy link

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
Copy link
Author

Anyone else have this issue or have any ideas?

@morrow95
Copy link
Author

Still wiuld like a response for this :)

@pitininja
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants