From cd7aeaef26bf05e42e789da6bc4a97118c40d616 Mon Sep 17 00:00:00 2001 From: moehm Date: Fri, 21 Mar 2014 18:40:44 +0100 Subject: The index.php starts the download. Also extra function to print empty folders. --- www/functions/func_content.php | 87 ++++++++++++++++++++++++++++++++++------ www/functions/func_download.php | 65 ++++++++++++++++++------------ www/functions/func_interface.php | 37 ----------------- www/functions/func_rewrite.php | 9 +---- 4 files changed, 117 insertions(+), 81 deletions(-) (limited to 'www/functions') diff --git a/www/functions/func_content.php b/www/functions/func_content.php index f7c4629..c750554 100755 --- a/www/functions/func_content.php +++ b/www/functions/func_content.php @@ -1,5 +1,23 @@ query("SELECT * FROM files WHERE parent=" . $file_id . " AND owner=" . $owner . ";"); @@ -19,21 +37,66 @@ function get_content($db, $file_id, $owner){ $count++; } -/* - var_dump($content); exit; - if($content[0][4] == "FILE"){ - if(!start_file_download($username, $folder_path)){ - echo "False!"; exit; - return false; - } else { - echo "True!"; exit; - return true; - } - } -*/ if(!empty($content)){ return $content; // returns everything listed in the folder which is commited as parameter } else { return false; // empty folder } } + +function get_path_to_empty_folder($db, $username, $folder_path){ + + if($_SESSION["login"] && $_SESSION["userid"] == $owner){ + if($_SESSION["login"] && $_SESSION["userid"] == $owner){} + } else { + $share ="AND share='PUBLIC'"; + } + + $folder_array_unsafe = explode("/",$folder_path); + $length = count($folder_array_unsafe); + + $root_db = $db->query("SELECT id FROM files WHERE parent=0 AND owner=" . SQLite3::escapeString($owner) . " AND fo lder='DIRECTORY' " . $share . ";"); + $root_ar = $root_db->fetchArray(SQLITE3_NUM); + $root_id = $root_ar[0]; + + if(empty($root_id[0])){ + return NOT_PUBLIC; + } + + $parentdir = $root_id; + + for($i=0; $i<$length; $i++){ + $parentdir_db = $db->query("SELECT id, parent FROM files WHERE owner=" . $owner . $share . " AND parent=" . $parentdir . " AND name='" . SQLite3::escapeString($folder_array_unsafe[$i]) . "';"); + $prim_id = $parentdir_db->fetchArray(SQLITE3_NUM); + + if($parentdir != $prim_id[1]){ + $wrong_folder = $folder_array_unsafe[$i]; + $working_path[0] = $wrong_folder; + + for($j=0; $j<$i; $j++){ + $working_path[$j] = $folder_array_unsafe[$j]; + } + + $lwp = count($working_path); + $working_path[$lwp] = $wrong_folder; + + return $working_path; // returns working path and wrong folder as an array + } + + } + + return false; +} + +function print_empty_folder($content){ + $length = count($content); + + $wrong_folder = $content[$length-1]; + $working_path[0] = $wrong_folder; // initialize empty array + + for($i=0; $i<$length-2, $i++){ + $working_path[$i] = $content[$i]; + } + + get_404($working_path, $wrong_folder); +} diff --git a/www/functions/func_download.php b/www/functions/func_download.php index 83db597..26b2188 100644 --- a/www/functions/func_download.php +++ b/www/functions/func_download.php @@ -1,10 +1,27 @@ 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; + } + +} + function start_file_download($user, $path){ $db = $GLOBALS["db"]; @@ -13,30 +30,27 @@ function start_file_download($user, $path){ $file_id = select_file_id($db, $owner, $path); -/* $file_id_db = $db->query("SELECT id, owner, share FROM files WHERE parent=" . $folder_id . "); - $file_id_ar = $file_id_db->fetchArray(SQLITE3_NUM); - $file_id = $file_id_ar[0]; - - $check_verification_db = $ - $check_verification_ar[1]; - $share = $check_verification_ar[2]; - + $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)){ - $var = download_file($db, $file_id); + if(download_file($db, $file_id)){ + return true; + } else { + return false; + } } else { if($share != "PUBLIC"){ return false; } - $var = download_file($db, $file_id); - } -*/ - - if(!download_file($db, $file_id)){ - return false; - } else { - return true; + if(download_file($db, $file_id)){ + return true; + } else { + return false; + } } } @@ -67,16 +81,17 @@ function download_file($db, $file_id){ $uploaddir = "../files/"; $gzip_file = $uploaddir . $file_hash . ".gz"; +//TODO: buffer output, print if reading == true + header("Content-Type: ".$file_mime); + header("Content-Disposition: attachment; filename=\"".$file_name."\""); + $uncompressed_file = readgzfile($gzip_file); - //if($uncompressed_file){ - header("Content-Type: ".$file_mime); - header("Content-Disposition: attachment; filename=\"".$file_name."\""); - $uncompressed_file = readgzfile($gzip_file); + if($uncompressed_file){ return true; - //} else { - // return false; - //} + } else { + return false; + } } diff --git a/www/functions/func_interface.php b/www/functions/func_interface.php index 192e94f..a86fe6d 100755 --- a/www/functions/func_interface.php +++ b/www/functions/func_interface.php @@ -1,42 +1,5 @@ query("SELECT folder FROM files WHERE id=".$file_id.";"); - $check_if_file_ar = $check_if_file_db->fetchArray(SQLITE3_NUM); - - //TODO: Instead of exit; let the browser start_download or print folder content - if($check_if_file_ar[0] == "FILE"){ - if(start_file_download($username, $folder_path)){ - exit; - return true; - } else { - exit; - return false; - } - } else { - $content = get_content($db, $file_id, $owner); - } - - - /*if(!$content){ - failure("This folder is empty."); - }*/ - - return $content; -} - -/*function print_browser($content){ - var_dump($content); -}*/ - function print_invite($var){ include("invite.php"); } diff --git a/www/functions/func_rewrite.php b/www/functions/func_rewrite.php index 48131f8..a58c7f9 100755 --- a/www/functions/func_rewrite.php +++ b/www/functions/func_rewrite.php @@ -17,15 +17,10 @@ function rewrite($db){ if($_SESSION["login"]){ header("Refresh: 0; /" . $_SESSION['username'] . "/" . $_GET["name"] . "/" . $folder . ""); - return false; - } else { + } - $wrong_folder = $_GET["name"]; - $working_path = $_GET["name"]; + return false; - get_404($working_path, $wrong_folder); - return false; - } } else { return true; } -- cgit v1.2.3