diff options
Diffstat (limited to 'www/functions/func_download.php')
| -rw-r--r-- | www/functions/func_download.php | 65 |
1 files changed, 40 insertions, 25 deletions
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 @@ <?php /* - Expected state: tested, broken. + Expected state: tested, but broken. Works if you are loged in, fatal error if not. */ +function check_if_file($db, $name, $folder_path){ + + $owner = user_id($db, $name); + + $file_id = select_file_id($db, $owner, $folder_path); + + $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; + } + +} + 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; + } } |
