summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32014-04-21 20:26:26 +0200
committerHorus32014-04-21 20:26:26 +0200
commit1301304d2ea739f550738e0fafc56d74a65905f4 (patch)
treee309ae34480b6f768c086ca685c8d56c0c95b266
parentdef084a19a19e1d5c77600c0c0967e5a8fed5b93 (diff)
downloadfiles.iamfabulous.de-1301304d2ea739f550738e0fafc56d74a65905f4.tar.gz
Added documentation for class and new methods.
-rw-r--r--www/class.files.php89
-rw-r--r--www/class.php53
-rwxr-xr-xwww/functions/func_content.php3
-rw-r--r--www/functions/func_download.php30
4 files changed, 142 insertions, 33 deletions
diff --git a/www/class.files.php b/www/class.files.php
index 7ce7d64..8f4090a 100644
--- a/www/class.files.php
+++ b/www/class.files.php
@@ -5,6 +5,9 @@ class file {
public $file;
public $DirList;
public $FileList;
+ public $OwnerId;
+ public $ParentId;
+ public $ParentName;
function __construct($val = null){
if($val == null){
@@ -32,6 +35,21 @@ class file {
$this->DirList = $DirRes;
$this->FileList = $FileRes;
+
+ $db = $GLOBALS["db"];
+
+ $OwnerId = user_id($GLOBALS["db"], $_GET["name"]);
+ $this->OwnerId = $OwnerId;
+
+ $FileId = select_file_id($db, $OwnerId, $_GET["folder"]);
+ $ParentId_db = $db->query("SELECT parent FROM files WHERE id=".$FileId.";");
+ $ParentId = $ParentId_db->fetchArray(SQLITE3_NUM);
+ $this->ParentId = $ParentId[0];
+
+ $ParentName_db = $db->query("SELECT name FROM files WHERE id=".$ParentId[0]);
+ $ParentName = $ParentName_db->fetchArray(SQLITE3_NUM);
+ $this->ParentName = $ParentName[0];
+
}
function NotFound(){
if($this->file == FILE_NOT_FOUND){
@@ -78,24 +96,14 @@ class file {
return $res;
}
}
- function getParent($val = null){
- $ar = $this->file;
- if($val != null){
- if(!preg_match("/^[0-9]+$/", $val)){
- return false;
- }
- return $ar[$val][1];
- } else {
- $res;
- for($i=0; $i<count($ar); $i++){
- $res[$i] = $ar[$i][1];
- }
- return $res;
- }
+ function getParentId(){
+ return $this->ParentId;
+ }
+ function getParentName(){
+ return $this->ParentName;
}
function getOwnerId(){
- $id = user_id($GLOBALS["db"], $_GET["name"]);
- return $id;
+ return $this->OwnerId;
}
function getOwnerName(){
return $_GET["name"];
@@ -160,7 +168,7 @@ class file {
return $res;
}
}
- function getHash($val = null){
+ function getShare($val = null){
$ar = $this->file;
if($val != null){
if(!preg_match("/^[0-9]+$/", $val)){
@@ -175,7 +183,7 @@ class file {
return $res;
}
}
- function getDownLink($val = null){
+ function getHash($val = null){
$ar = $this->file;
if($val != null){
if(!preg_match("/^[0-9]+$/", $val)){
@@ -190,6 +198,51 @@ class file {
return $res;
}
}
+ function getDownLink($val = null){
+ $ar = $this->file;
+ if($val != null){
+ if(!preg_match("/^[0-9]+$/", $val)){
+ return false;
+ }
+ return $ar[$val][9];
+ } else {
+ $res;
+ for($i=0; $i<count($ar); $i++){
+ $res[$i] = $ar[$i][9];
+ }
+ return $res;
+ }
+ }
+ function getUploadTime($val = null){
+ $ar = $this->file;
+ if($val != null){
+ if(!preg_match("/^[0-9]+$/", $val)){
+ return false;
+ }
+ return $ar[$val][10];
+ } else {
+ $res;
+ for($i=0; $i<count($ar); $i++){
+ $res[$i] = $ar[$i][10];
+ }
+ return $res;
+ }
+ }
+ function getLastTime($val = null){
+ $ar = $this->file;
+ if($val != null){
+ if(!preg_match("/^[0-9]+$/", $val)){
+ return false;
+ }
+ return $ar[$val][11];
+ } else {
+ $res;
+ for($i=0; $i<count($ar); $i++){
+ $res[$i] = $ar[$i][11];
+ }
+ return $res;
+ }
+ }
function getAll(){
return $this->file;
}
diff --git a/www/class.php b/www/class.php
new file mode 100644
index 0000000..672e471
--- /dev/null
+++ b/www/class.php
@@ -0,0 +1,53 @@
+<?php
+include("include.php");
+
+$f = new file();
+
+
+echo "\$f = new file(); <br> <br> \$f->NotFound() [bool]<br>";
+var_dump($f->NotFound());
+echo "<br><br> \$f->isEmpty() [bool]<br>";
+var_dump($f->isEmpty());
+echo "<br><br> \$f->isFile() [bool]<br>";
+var_dump($f->isFile());
+echo "<br><br> \$f->getDim() [int]<br>";
+var_dump($f->getDim());
+echo "<br><br> \$f->getId() [int]<br>";
+var_dump($f->getId());
+echo "<br><br> \$f->getParentId() [int]<br>";
+var_dump($f->getParentId());
+echo "<br><br> \$f->getParentName() [string]<br>";
+var_dump($f->getParentName());
+echo "<br><br> \$f->getOwnerId() [int]<br>";
+var_dump($f->getOwnerId());
+echo "<br><br> \$f->getOwnerName() [string]<br>";
+var_dump($f->getOwnerName());
+echo "<br><br> \$f->getName() [array]<br>";
+var_dump($f->getName());
+echo "<br><br> \$f->getType() (Directory or File) [array]<br>";
+var_dump($f->getType());
+echo "<br><br> \$f->getMime() [array]<br>";
+var_dump($f->getMime());
+echo "<br><br> \$f->getSize() (in bytes) [array]<br>";
+var_dump($f->getSize());
+echo "<br><br> \$f->getShare() [array]<br>";
+var_dump($f->getShare());
+echo "<br><br> \$f->getHash() [array]<br>";
+var_dump($f->getHash());
+echo "<br><br> \$f->getDownLink() [array]<br>";
+var_dump($f->getDownLink());
+echo "<br><br> \$f->getUploadTime() [array]<br>";
+var_dump($f->getUploadTime());
+echo "<br><br> \$f->getLastTime() (Time File was last downloaded) [array]<br>";
+var_dump($f->getLastTime());
+echo "<br><br> \$f->getAll() [2D array]<br>";
+var_dump($f->getAll());
+echo "<br><br> \$f->getDirList() [array]<br>";
+var_dump($f->getDirList());
+echo "<br><br> \$f->getFileList() [array]<br>";
+var_dump($f->getFileList());
+echo "<br><br> \$f->getDirNum() [int] <br>";
+var_dump($f->getDirNum());
+echo "<br><br> \$f->getFileNum() [int] <br>";
+var_dump($f->getFileNum());
+echo "<br><br>";
diff --git a/www/functions/func_content.php b/www/functions/func_content.php
index ad0c87e..853adc1 100755
--- a/www/functions/func_content.php
+++ b/www/functions/func_content.php
@@ -44,6 +44,9 @@ function get_content($db, $file_id, $owner){
$content[$count][6] = $row[6];
$content[$count][7] = $row[7];
$content[$count][8] = $row[8];
+ $content[$count][9] = $row[9];
+ $content[$count][10] = $row[10];
+ $content[$count][11] = $row[11];
$count++;
}
diff --git a/www/functions/func_download.php b/www/functions/func_download.php
index 576320c..2b4acc5 100644
--- a/www/functions/func_download.php
+++ b/www/functions/func_download.php
@@ -39,9 +39,10 @@ function start_file_download($user, $path){
$file_ar = $file_db->fetchArray(SQLITE3_NUM);
$file_owner = $file_ar[0];
$share = $file_ar[1];
+ $force_download = false;
if($_SESSION["login"] && ($_SESSION["userid"] == $file_owner)){
- if(download_file($db, $file_id)){
+ if(download_file($db, $file_id, $force_download)){
return true;
} else {
return false;
@@ -51,7 +52,7 @@ function start_file_download($user, $path){
return false;
}
- if(download_file($db, $file_id)){
+ if(download_file($db, $file_id, $force_download)){
return true;
} else {
return false;
@@ -67,7 +68,7 @@ function check_file_hash($db, $file_id, $download_hash){
$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"){
+ if($check_hash_ar[1] != "FILE" || !$check_hash_ar){
return DOWNLOAD_NOT_FILE;
}
@@ -79,15 +80,18 @@ function check_file_hash($db, $file_id, $download_hash){
}
}
- if(!download_file($db, $file_id)){
- return false;
- } else {
+ $force_download = true;
+
+ $var = download_file($db, $file_id, $force_download);
+ if($var){
return true;
+ } else {
+ return $var;
}
}
-function download_file($db, $file_id){
+function download_file($db, $file_id, $force_download){
$file_db = $db->query("SELECT name, mime, size, hash FROM files WHERE id=". SQLite3::escapeString($file_id).";");
$file_ar = $file_db->fetchArray(SQLITE3_NUM);
@@ -102,15 +106,13 @@ function download_file($db, $file_id){
//TODO: buffer output, print if reading == true
- header("Content-Type: ".$file_mime);
-/*
- if(!preg_match("/^image\/.+/", $file_mime)){
+ header("Content-Type: ".$file_mime."");
+ if(preg_match("/^application\/.+/", $file_mime) || $force_download){
header("Content-Disposition: attachment; filename=\"".$file_name."\"");
} else {
- header("filename=".$file_name."");
+ header('filename="'.$file_name.'"');
}
-*/
- header("filename=".$file_name."");
+
header("Content-Length: ".$file_size);
set_time_limit(0);
$uncompressed_file = readgzfile($gzip_file);
@@ -121,6 +123,4 @@ function download_file($db, $file_id){
} else {
return false;
}
-
-
}