-
+
@@ -2809,29 +2817,142 @@ function fm_get_onlineViewer_exts()
return array('doc', 'docx', 'xls', 'xlsx', 'pdf', 'ppt', 'pptx', 'ai', 'psd', 'dxf', 'xps', 'rar', 'odt', 'ods');
}
+function fm_get_file_mimes($extension)
+{
+ $fileTypes['swf'] = 'application/x-shockwave-flash';
+ $fileTypes['pdf'] = 'application/pdf';
+ $fileTypes['exe'] = 'application/octet-stream';
+ $fileTypes['zip'] = 'application/zip';
+ $fileTypes['doc'] = 'application/msword';
+ $fileTypes['xls'] = 'application/vnd.ms-excel';
+ $fileTypes['ppt'] = 'application/vnd.ms-powerpoint';
+ $fileTypes['gif'] = 'image/gif';
+ $fileTypes['png'] = 'image/png';
+ $fileTypes['jpeg'] = 'image/jpg';
+ $fileTypes['jpg'] = 'image/jpg';
+ $fileTypes['rar'] = 'application/rar';
+
+ $fileTypes['ra'] = 'audio/x-pn-realaudio';
+ $fileTypes['ram'] = 'audio/x-pn-realaudio';
+ $fileTypes['ogg'] = 'audio/x-pn-realaudio';
+
+ $fileTypes['wav'] = 'video/x-msvideo';
+ $fileTypes['wmv'] = 'video/x-msvideo';
+ $fileTypes['avi'] = 'video/x-msvideo';
+ $fileTypes['asf'] = 'video/x-msvideo';
+ $fileTypes['divx'] = 'video/x-msvideo';
+
+ $fileTypes['mp3'] = 'audio/mpeg';
+ $fileTypes['mp4'] = 'audio/mpeg';
+ $fileTypes['mpeg'] = 'video/mpeg';
+ $fileTypes['mpg'] = 'video/mpeg';
+ $fileTypes['mpe'] = 'video/mpeg';
+ $fileTypes['mov'] = 'video/quicktime';
+ $fileTypes['swf'] = 'video/quicktime';
+ $fileTypes['3gp'] = 'video/quicktime';
+ $fileTypes['m4a'] = 'video/quicktime';
+ $fileTypes['aac'] = 'video/quicktime';
+ $fileTypes['m3u'] = 'video/quicktime';
+
+ $fileTypes['php'] = ['application/x-php'];
+ $fileTypes['html'] = ['text/html'];
+ $fileTypes['txt'] = ['text/plain'];
+ return $fileTypes[$extension];
+}
+
/**
* This function scans the files and folder recursively, and return matching files
* @param string $dir
+ * @param string $filter
* @return json
*/
function scan($dir, $filter = '') {
$path = FM_ROOT_PATH.'/'.$dir;
- $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
- $rii = new RegexIterator($ite, "/(".$filter.")/i");
+ if($dir) {
+ $ite = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
+ $rii = new RegexIterator($ite, "/(" . $filter . ")/i");
- $files = array();
- foreach ($rii as $file) {
- if (!$file->isDir()) {
- $fileName = $file->getFilename();
- $location = str_replace(FM_ROOT_PATH, '', $file->getPath());
- $files[] = array(
- "name" => $fileName,
- "type" => "file",
- "path" => $location,
- );
- }
+ $files = array();
+ foreach ($rii as $file) {
+ if (!$file->isDir()) {
+ $fileName = $file->getFilename();
+ $location = str_replace(FM_ROOT_PATH, '', $file->getPath());
+ $files[] = array(
+ "name" => $fileName,
+ "type" => "file",
+ "path" => $location,
+ );
+ }
+ }
+ return $files;
+ }
+}
+
+/*
+Parameters: downloadFile(File Location, File Name,
+max speed, is streaming
+If streaming - videos will show as videos, images as images
+instead of download prompt
+https://stackoverflow.com/a/13821992/1164642
+*/
+
+function fm_download_file($fileLocation, $fileName, $chunkSize = 1024)
+{
+ if (connection_status() != 0)
+ return (false);
+ $extension = pathinfo($fileName, PATHINFO_EXTENSION);
+
+ $contentType = fm_get_file_mimes($extension);
+ header("Cache-Control: public");
+ header("Content-Transfer-Encoding: binary\n");
+ header('Content-Type: $contentType');
+
+ $contentDisposition = 'attachment';
+
+
+ if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) {
+ $fileName = preg_replace('/\./', '%2e', $fileName, substr_count($fileName, '.') - 1);
+ header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
+ } else {
+ header("Content-Disposition: $contentDisposition;filename=\"$fileName\"");
}
- return $files;
+
+ header("Accept-Ranges: bytes");
+ $range = 0;
+ $size = filesize($fileLocation);
+
+ if (isset($_SERVER['HTTP_RANGE'])) {
+ list($a, $range) = explode("=", $_SERVER['HTTP_RANGE']);
+ str_replace($range, "-", $range);
+ $size2 = $size - 1;
+ $new_length = $size - $range;
+ header("HTTP/1.1 206 Partial Content");
+ header("Content-Length: $new_length");
+ header("Content-Range: bytes $range$size2/$size");
+ } else {
+ $size2 = $size - 1;
+ header("Content-Range: bytes 0-$size2/$size");
+ header("Content-Length: " . $size);
+ }
+
+ if ($size == 0) {
+ die('Zero byte file! Aborting download');
+ }
+ @ini_set('magic_quotes_runtime', 0);
+ $fp = fopen("$fileLocation", "rb");
+
+ fseek($fp, $range);
+
+ while (!feof($fp) and (connection_status() == 0)) {
+ set_time_limit(0);
+ print(@fread($fp, 1024*$chunkSize));
+ flush();
+ ob_flush();
+ sleep(1);
+ }
+ fclose($fp);
+
+ return ((connection_status() == 0) and !connection_aborted());
}
/**
diff --git a/translation.json b/translation.json
index c10fdb1..ca63b28 100644
--- a/translation.json
+++ b/translation.json
@@ -1,6 +1,6 @@
{
"appName": "Tiny File Manager",
- "version": "2.4.1",
+ "version": "2.4.2",
"language": [
{
"name": "فارسی",