Passed
Push — master ( 8afea9...0ea5f2 )
by Goffy
03:26
created

download.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
*/
14
15
/**
16
 * wgFileManager module for xoops
17
 *
18
 * @copyright    2021 XOOPS Project (https://xoops.org)
19
 * @license      GPL 2.0 or later
20
 * @package      wgfilemanager
21
 * @author       Goffy - Wedega - Email:[email protected] - Website:https://xoops.wedega.com
22
 */
23
24
use Xmf\Request;
0 ignored issues
show
This use statement conflicts with another class in this namespace, Request. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
25
use XoopsModules\Wgfilemanager;
26
use XoopsModules\Wgfilemanager\Constants;
27
use XoopsModules\Wgfilemanager\Common;
28
29
require __DIR__ . '/header.php';
30
31
$op     = Request::getString('op', 'list');
32
$fileId = Request::getInt('file_id');
33
34
// get download vars
35
$fileObj = $fileHandler->get($fileId);
36
// check permissions
37
$permDownload = $permissionsHandler->getPermDownloadFileFromDir($fileObj->getVar('directory_id'));
38
if (!$permDownload) {
39
    \redirect_header('index.php?op=list', 3, \_MA_WGFILEMANAGER_NO_PERM_DOWNLOAD);
40
}
41
$fileName = $fileObj->getVar('name');
42
$fileMimetype = $fileObj->getVar('mimetype');
43
$fileSize = $fileObj->getVar('size');
44
$dirObj = $directoryHandler->get($fileObj->getVar('directory_id'));
45
$file = \WGFILEMANAGER_REPO_PATH . $dirObj->getVar('fullpath') . '/' . $fileName;
46
if (!\file_exists($file)) {
47
    \redirect_header('index.php?op=list', 3, \_MA_WGFILEMANAGER_FILE_ERROR_DONOTEXIST);
48
}
49
50
$fp = fopen($file, 'rb');
51
header('Content-type: ' . $fileMimetype);
52
header('Content-Length: ' . $fileSize);
53
header('Content-Disposition: attachment; filename=' . $fileName);
54
header('Content-Transfer-Encoding: binary');
55
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
56
fpassthru($fp);
57
58
59
60