diff options
Diffstat (limited to 'www/functions/notused/func_download.php')
| -rw-r--r-- | www/functions/notused/func_download.php | 123 |
1 files changed, 0 insertions, 123 deletions
diff --git a/www/functions/notused/func_download.php b/www/functions/notused/func_download.php deleted file mode 100644 index 26b25b1..0000000 --- a/www/functions/notused/func_download.php +++ /dev/null @@ -1,123 +0,0 @@ -<?php - -/* - Expected state: tested, should work. -*/ - -function check_if_file($db, $name, $folder_path){ - - $owner = user_id($db, $name); - - $file_id = select_file_id($db, $owner, $folder_path); - - if($file_id){ - $check_if_file_db = $db->query("SELECT folder FROM files WHERE id=".$file_id.";"); - $check_if_file_ar = $check_if_file_db->fetchArray(SQLITE3_NUM); - - if($check_if_file_ar[0] == "FILE"){ - return true; - } else { - return false; - } - } else { - //$content = get_path_to_empty_folder($db, $name, $folder_path); - //print_empty_folder($content); - //get_404("/", "Protected file"); - return false; - } -} - -function start_file_download($user, $path){ - - $db = $GLOBALS["db"]; - - $owner = user_id($db, $user); - - $file_id = select_file_id($db, $owner, $path); - - $file_db = $db->query("SELECT owner, share FROM files WHERE id=" . $file_id . ";"); - $file_ar = $file_db->fetchArray(SQLITE3_NUM); - $file_owner = $file_ar[0]; - $share = $file_ar[1]; - - if($_SESSION["login"] && ($_SESSION["userid"] == $file_owner)){ - if(download_file($db, $file_id)){ - return true; - } else { - return false; - } - } else { - if($share != "PUBLIC"){ - return false; - } - - if(download_file($db, $file_id)){ - return true; - } else { - return false; - } - } -} - -function check_file_hash($db, $file_id, $download_hash){ - if(preg_match("/[^0-9]/", $file_id)){ - return DOWNLOAD_FALSE_ID; - } - - $check_hash_db = $db->query("SELECT owner, folder, share, download_link FROM files WHERE id=" . SQLite3::escapeString($file_id).";"); - $check_hash_ar = $check_hash_db->fetchArray(SQLITE3_NUM); - - if($check_hash_ar[1] != "FILE"){ - return DOWNLOAD_NOT_FILE; - } - - if($check_hash_ar[2] != "PUBLIC"){ - if($_SESSION["userid"] != $check_hash_ar[0]){ - if($check_hash_ar[3] != $download_hash){ - return DOWNLOAD_PRIVATE_FILE; - } - } - } - - if(!download_file($db, $file_id)){ - return false; - } else { - return true; - } - -} - -function download_file($db, $file_id){ - - $file_db = $db->query("SELECT name, mime, size, hash FROM files WHERE id=". SQLite3::escapeString($file_id).";"); - $file_ar = $file_db->fetchArray(SQLITE3_NUM); - - $file_name = $file_ar[0]; - $file_mime = $file_ar[1]; - $file_size = $file_ar[2]; - $file_hash = $file_ar[3]; - - $uploaddir = "../files/"; - $gzip_file = $uploaddir . $file_hash . ".gz"; - -//TODO: buffer output, print if reading == true - - header("Content-Type: ".$file_mime); - - if(!preg_match("/^image\/.+/", $file_mime)){ - header("Content-Disposition: attachment; filename=\"".$file_name."\""); - } else { - header("filename=".$file_name.""); - } - header("Content-Length: ".$file_size); - set_time_limit(0); - $uncompressed_file = readgzfile($gzip_file); - - if($uncompressed_file){ - return true; - } else { - return false; - } - - -} |
