Skip to content

Commit

Permalink
Added option to download files indirect via php script
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikescher committed Jun 22, 2016
1 parent fd868e4 commit 1d83af8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 3 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ It supports simultaneous downloads in background.
2. Set security to true
3. Find a password, hash it with md5 and replace the value of password.

## Troubleshooting
1. If you don't want a password set `security` to false
2. If you have problems downloading files, check the permissions and try setting `indirect_download` to true

Example (chosen password is root):

```
Expand Down
4 changes: 2 additions & 2 deletions class/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Session
{
private $config = [];
public $config = [];

private static $_instance;

Expand Down Expand Up @@ -61,4 +61,4 @@ public function logout()
}
}

?>
?>
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"password" => "63a9f0ea7bb98050796b649e85481845",
"outputFolder" => "downloads",
"extracter" => "avconv",
"indirect_download" => false,
"max_dl" => 3);

?>
31 changes: 31 additions & 0 deletions getfile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php
require_once 'class/Session.php';
require_once 'class/FileHandler.php';

$session = Session::getInstance();
$file = new FileHandler;

if(!$session->is_logged_in())
{
header("Location: login.php");
}

$filename = $_GET['file'];

if (strpos($filename, DIRECTORY_SEPARATOR) !== false || empty($filename))
{
die("Invalid parameter 'file'");
}

$path = $file->get_downloads_folder() . DIRECTORY_SEPARATOR . $filename;

$fp = fopen($path, 'rb');

header("Content-Type: application/octet-stream");
header('Content-Disposition: attachment; filename="' . $filename . '"');
header("Content-Length: " . filesize($path));


fpassthru($fp);

exit;
9 changes: 8 additions & 1 deletion list.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@
foreach($files as $f)
{
echo "<tr>";
echo "<td><a href=\"".$file->get_downloads_folder().'/'.$f["name"]."\" download>".$f["name"]."</a></td>";
if ($session->config["indirect_download"])
{
echo "<td><a href=\"getfile.php?file=".urlencode($f["name"])."\" download>".$f["name"]."</a></td>";
}
else
{
echo "<td><a href=\"".$file->get_downloads_folder().'/'.$f["name"]."\" download>".$f["name"]."</a></td>";
}
echo "<td>".$f["size"]."</td>";
echo "<td><a href=\"./list.php?delete=$i&type=$t\" class=\"btn btn-danger btn-sm\">Delete</a></td>";
echo "</tr>";
Expand Down

0 comments on commit 1d83af8

Please sign in to comment.