IndexController.class.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class IndexController extends BaseController {
  5. public function index(){
  6. //不存在安装文件夹的,表示已经安装过
  7. if(!file_exists("./install")){
  8. //跳转到web目录
  9. header("location:./web/#/");
  10. exit();
  11. }
  12. if(file_exists("./install") && file_exists("./install/install.lock") && $this->new_is_writeable("./install") && $this->new_is_writeable("./install/install.lock") ){
  13. //跳转到web目录
  14. header("location:./web/#/");
  15. exit();
  16. }
  17. //其他情况都跳转到安装页面
  18. header("location:./install/index.php");
  19. }
  20. /**
  21. * 判断 文件/目录 是否可写(取代系统自带的 is_writeable 函数)
  22. *
  23. * @param string $file 文件/目录
  24. * @return boolean
  25. */
  26. public function new_is_writeable($file) {
  27. if (is_dir($file)){
  28. $dir = $file;
  29. if ($fp = @fopen("$dir/test.txt", 'w')) {
  30. @fclose($fp);
  31. @unlink("$dir/test.txt");
  32. $writeable = 1;
  33. } else {
  34. $writeable = 0;
  35. }
  36. } else {
  37. if ($fp = @fopen($file, 'a+')) {
  38. @fclose($fp);
  39. $writeable = 1;
  40. } else {
  41. $writeable = 0;
  42. }
  43. }
  44. return $writeable;
  45. }
  46. }