file_index.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. require_once 'checklogin.inc';
  3. require_once "../path.php";
  4. require_once "../public/_pdo.php";
  5. require_once "../public/function.php";
  6. if(isset($_POST["op"])){
  7. $op=$_POST["op"];
  8. }
  9. if(isset($_POST["id"])){
  10. $id=$_POST["id"];
  11. }
  12. if(isset($_POST["filename"])){
  13. $filename=$_POST["filename"];
  14. }
  15. if(isset($_POST["doc_id"])){
  16. $doc_id=$_POST["doc_id"];
  17. }
  18. if(isset($_POST["field"])){
  19. $field=$_POST["field"];
  20. }
  21. if(isset($_POST["value"])){
  22. $value=$_POST["value"];
  23. }
  24. if($_COOKIE["uid"]){
  25. $uid=$_COOKIE["uid"];
  26. }
  27. else{
  28. echo "尚未登录";
  29. exit;
  30. }
  31. PDO_Connect("sqlite:"._FILE_DB_FILEINDEX_);
  32. switch($op){
  33. case "list":
  34. break;
  35. case "get";
  36. $query="select * from fileindex where user_id='$uid' AND id='{$doc_id}'";
  37. $Fetch = PDO_FetchAll($query);
  38. echo json_encode($Fetch, JSON_UNESCAPED_UNICODE);
  39. break;
  40. case "getall";
  41. //
  42. $time=time();
  43. $query="select * from fileindex where user_id='$uid' AND id='{$_POST["doc_id"]}'";
  44. $Fetch = PDO_FetchAll($query);
  45. $iFetch=count($Fetch);
  46. if($iFetch>0){
  47. echo json_encode($Fetch[0], JSON_UNESCAPED_UNICODE);
  48. }
  49. break;
  50. case "set";
  51. //修改文件索引数据库
  52. if($field=="accese_time"){
  53. $value=mTime();
  54. }
  55. $doc_id=$_POST["doc_id"];
  56. $query="UPDATE fileindex SET $field='$value' where user_id='$uid' AND id='{$doc_id}'";
  57. $stmt = @PDO_Execute($query);
  58. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  59. $error = PDO_ErrorInfo();
  60. echo json_encode(array("error"=>$error[2],"message"=>$query), JSON_UNESCAPED_UNICODE);
  61. }
  62. else{
  63. echo json_encode(array("error"=>"","message"=>$query), JSON_UNESCAPED_UNICODE);
  64. }
  65. break;
  66. case "share":
  67. //修改文件索引数据库
  68. if(isset($_POST["file"])){
  69. if(isset($_POST["share"])){
  70. $share=$_POST["share"];
  71. }
  72. else{
  73. $share=0;
  74. }
  75. $fileList=$_POST["file"];
  76. $aFileList=str_getcsv($fileList);
  77. if(count($aFileList)>0){
  78. $strFileList="(";
  79. foreach($aFileList as $file) {
  80. $strFileList.="'{$file}',";
  81. }
  82. $strFileList=mb_substr($strFileList, 0,mb_strlen($strFileList,"UTF-8")-1,"UTF-8");
  83. $strFileList.=")";
  84. $query="UPDATE fileindex SET share='$share' where user_id='$uid' AND id in $strFileList";
  85. $stmt = @PDO_Execute($query);
  86. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  87. $error = PDO_ErrorInfo();
  88. echo "error:{$error[2]}";
  89. }
  90. else{
  91. echo "ok".$query;
  92. }
  93. }
  94. }
  95. break;
  96. case "delete"://移到回收站
  97. {
  98. if(isset($_POST["file"])){
  99. $fileList=$_POST["file"];
  100. $aFileList=str_getcsv($fileList);
  101. if(count($aFileList)>0){
  102. $strFileList="(";
  103. foreach($aFileList as $file) {
  104. $strFileList.="'{$file}',";
  105. }
  106. $strFileList=mb_substr($strFileList, 0,mb_strlen($strFileList,"UTF-8")-1,"UTF-8");
  107. $strFileList.=")";
  108. $query="UPDATE fileindex SET status='0',share='0' where user_id='$uid' AND id in $strFileList";
  109. $stmt = @PDO_Execute($query);
  110. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  111. $error = PDO_ErrorInfo();
  112. echo "error:{$error[2]}";
  113. }
  114. else{
  115. echo "ok";
  116. }
  117. }
  118. }
  119. break;
  120. }
  121. case "restore"://从回收站中恢复
  122. if(isset($_POST["file"])){
  123. $fileList=$_POST["file"];
  124. $aFileList=str_getcsv($fileList);
  125. if(count($aFileList)>0){
  126. $strFileList="(";
  127. foreach($aFileList as $file) {
  128. $strFileList.="'{$file}',";
  129. }
  130. $strFileList=mb_substr($strFileList, 0,mb_strlen($strFileList,"UTF-8")-1,"UTF-8");
  131. $strFileList.=")";
  132. $query="UPDATE fileindex SET status='1' where user_id='$uid' AND id in $strFileList";
  133. $stmt = @PDO_Execute($query);
  134. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  135. $error = PDO_ErrorInfo();
  136. echo "error:{$error[2]}";
  137. }
  138. else{
  139. echo "ok";
  140. }
  141. }
  142. }
  143. break;
  144. case "remove":
  145. //彻底删除文件
  146. if(isset($_POST["file"])){
  147. $fileList=$_POST["file"];
  148. $aFileList=str_getcsv($fileList);
  149. if(count($aFileList)>0){
  150. $strFileList="(";
  151. //删除文件
  152. foreach($aFileList as $file) {
  153. if(!unlink($dir.$file)){
  154. echo("Error deleting $file");
  155. }
  156. $strFileList.="'{$file}',";
  157. }
  158. $strFileList=mb_substr($strFileList, 0,mb_strlen($strFileList,"UTF-8")-1,"UTF-8");
  159. $strFileList.=")";
  160. //删除记录
  161. $query="DELETE FROM fileindex WHERE user_id='$uid' AND id in $strFileList";
  162. $stmt = @PDO_Execute($query);
  163. if (!$stmt || ($stmt && $stmt->errorCode() != 0)) {
  164. $error = PDO_ErrorInfo();
  165. echo "error:{$error[2]}";
  166. }
  167. else{
  168. echo "删除".count($aFileList)."个文件。";
  169. }
  170. }
  171. }
  172. break;
  173. case "remove_all":
  174. // 清空回收站
  175. break;
  176. }
  177. ?>