-
Notifications
You must be signed in to change notification settings - Fork 2
/
filedispenser.php
47 lines (43 loc) · 1.27 KB
/
filedispenser.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
$work_dir= "/var/www/htdocs/selfservice";
$storage_dir = "/var/www/htdocs/selfservice/storage/";
$filePaths = $_POST["filePaths"];
$filePaths = htmlspecialchars($filePaths);
$command = "python ".$work_dir."/python/file_grabber.py"." \"".$filePaths."\"";
$command = escapeshellcmd($command);
$output = shell_exec($command);
$file = trim($storage_dir.$output);
if ( 0 == filesize($file))
{
?>
<script>
window.alert('No results returned, Sorry ! ');
</script>
<?php
}
else{
echo "download";
downloadFile($output,$storage_dir);
}
function downloadFile($file, $storage_dir) {
$file = trim($file);
$fullPath = $storage_dir.$file;
if (file_exists($fullPath)) { ## doesn't work
echo "the file exits";
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($storage_dir.$file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($storage_dir.$file));
ob_clean();
flush();
readfile($storage_dir.$file);
exit;
}
else {
echo "the file wasn't found";
}
}