goldsky/FileDownload-R

Not working with get variable in URL

vierkantemeter opened this issue · 0 comments

In response to my form post (http://forums.modx.com/thread/70168/support-comments-for-filedownload-r-1-0-0-beta2#dis-post-506596).

I'm having a problem with FileDownloadLink. I'm using it in a getResources tpl to provide direct downloads. I'm providing the link to the resource with FileDownloadLink to hide the path. This works great on most pages but not on a specific resource where there is a get variable in the URL (necessary to show the correct files). The url for this is: www.mywebsite.nl/docs?cat=7

When I click a download link 2 things happen:
- the page reloads but without the variable 'cat' thus the wrong content is shown
- no file is downloaded

Here is my solution. My variable ("voor") is hardcoded, so the code needs to be altered. But it might help you.

Snippet FileDownloadLink around line 322

if (!empty($queries['id'])) {
        // non FURL
        $baseRef = $xRef[0] . '?id=' . $queries['id'];
    } 
    else if (!empty($queries['voor'])) {
        // With "voor" var in URL
        $baseRef = $xRef[0] . '?voor=' . $queries['voor'];
    }
    else {
        $baseRef = $xRef[0];
    }

File core/components/filedownloadr/models/filedownload/filedownload.class.php around line 1005

else {
            if ($_GET['voor']) {
                $args = 'voor=' .$_GET['voor'];
            }
            $args .= '&fdlfile=' . $hash;
            $url = $this->modx->makeUrl($this->modx->resource->get('id'), $ctx, $args);
            $link['url'] = $url;
        }

MODX 2.2.15
Fliedownload R 1.1.7