Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
RewriteEngine on
RewriteCond $1 !^(index\.php|static|images|js|css|robots\.txt)
RewriteRule ^(.*)$ /nangua/index.php/$1 [L]
RewriteEngine on
RewriteCond $1 !^(index\.php|static|uploadimgs|images|js|css|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
2 changes: 1 addition & 1 deletion application/config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['hostname'] = '127.0.0.1';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'nangua';
Expand Down
5 changes: 3 additions & 2 deletions application/config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@
|
*/

$route['default_controller'] = "welcome";
$route['default_controller'] = "login";
$route['404_override'] = '';

$route['upload'] = 'UploadImg';
$route['upload/create'] = 'UploadImg/create';

/* End of file routes.php */
/* Location: ./application/config/routes.php */
145 changes: 145 additions & 0 deletions application/controllers/UploadImg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

include_once(APPPATH."core/NG_Controller.php");

class UploadImg extends NG_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('img_records');
$this->load->helper('url_helper');
$this->load->helper('url');
$this->load->library("session");
$this->load->helper('html');
$this->load->library('image_lib');
$this->load->library('zip');
}
public function index()
{
$username = $this->session->userdata('username');
if($username == 'admin')
{
$data['img_records'] = $this->img_records->getInfoByUser();
}
else
{
$data['img_records'] = $this->img_records->getInfoByUser($username);
}
$this->load->view('templates/header');
$this->load->view('img_records/index',$data);
$this->load->view('templates/footer');
}
public function create()
{
$this->load->helper('form');
if($_SERVER["REQUEST_METHOD"] == "POST") {
//检查数据合法性
//1.设置合法性规则
$this->load->library('form_validation');
$this->form_validation->set_rules('floor','楼层','required');
$this->form_validation->set_rules('total_floor','总楼层','greater_than[1]|required');
$this->form_validation->set_rules('title','标题','required');

//2.执行合法性检查
if($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header');
$this->load->view('img_records/create');
$this->load->view('templates/footer');
return;
}
//执行sql,并返回insert的id
$id = $this->img_records->insert();
//文件上传、保存
//判断是否呀
$username = $this->session->userdata('username');
$savePath = 'uploadimgs/'.$username.'/'.$id.'/';
if (!file_exists($savePath)){ mkdir($savePath,0755,true);}
$config['upload_path'] = $savePath ;
$config['allowed_types'] = 'gif|jpg|png|jpeg';
//$config['max_size'] = 100000000;
// $config['max_width'] = 1024;
// $config['max_height'] = 768;
//初始化文件上传类
$this->load->library('upload',$config);
//开始上传
for($i = 1;$i<=12;$i++)
{
$this->upload->do_upload('userfile'.$i);
// $this->upload->do_upload('userfile2')
}
//返回至index列表
$this->index();
}else if($_SERVER["REQUEST_METHOD"] == "GET") {
$this->load->view('templates/header');
$this->load->view('img_records/create');
$this->load->view('templates/footer');
return;
}
else{
show_error('错误的请求',404,'发生了如下错误:');
}
}
public function show()
{
$data = array('imgs' => $this->getImgsInfo());
$this->load->view('img_records/show',$data);
}
public function download()
{
$imgPath = $this->getImgsPath();
$this->zip->read_dir($imgPath,FALSE);
$this->zip->download($this->getUserName().'_'.$this->uri->segment(3).'_zip');
}
private function getImgsInfo(){
$img_basepath = $this->getImgsPath();
$dir = dir($img_basepath);
$files = array();
while (($file = $dir->read()) !== false)
{
if($file == '.' || $file =='..')continue;
$files[$file] = $img_basepath.$file;
}
$dir->close();
return $files;
}
private function getImgsPath(){
$username = $this->getUserName();
$id = $this->uri->segment(3);
return 'uploadimgs/'.$username.'/'.$id.'/';
}
private function getUserName(){
return $this->session->userdata('username');
}
public function deldir($dir) {
//先删除目录下的文件:
$dh=opendir($dir);
while ($file=readdir($dh)) {
if($file!="." && $file!="..") {
$fullpath=$dir."/".$file;
if(!is_dir($fullpath)) {
unlink($fullpath);
} else {
deldir($fullpath);
}
}
}

closedir($dh);
//删除当前文件夹:
if(rmdir($dir)) {
return true;
} else {
return false;
}
}
public function delete(){
echo "libing test delete here!";
$username = $this->session->userdata('username');
$id = $this->uri->segment(3);
$img_basepath = 'uploadimgs/'.$username.'/'.$id.'/';
$this->deldir($img_basepath);
$this->img_records->delete($id);
redirect("/UploadImg/index");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function loginHandler(){
$existedUser = $this->login_model->checkUser();
$data["existedUser"] = $existedUser;
if ($existedUser==true) {
$userdata = array('username' => $username );
$userdata = array('username' => $username);
$this->session->set_userdata($userdata);
echo "true";
}else{
Expand Down
15 changes: 15 additions & 0 deletions application/core/NG_Controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

class NG_Controller extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('session');
if(!isset($this->session->userdata['username']))
{
$this->load->helper('url');
redirect('/login');
#header('Location: /login');
}
}
}
52 changes: 52 additions & 0 deletions application/models/img_records.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
class img_records extends CI_Model {
public function __construct()
{
$this->load->database();
}
public function getInfoByUser($username = null)
{
if($username)
{
$query = $this->db->get_where('img_records',array('username' => $username));
}
else
{
$query = $this->db->get('img_records');
}
return $query->result_array();
}
public function insert()
{
$this->load->helper('url');
$data = array(
//'username' => $this->input->post('username'),
'username' => $this->session->userdata('username'),
'title' => $this->input->post('title'),
'addr' => $this->input->post('addr'),
'square' => $this->input->post('square'),
'agency' => $this->input->post('agency'),
'village' => $this->input->post('village'),
'wechat_num' => $this->input->post('wechat_num'),
'canton' => $this->input->post('canton'),
'landmark' => $this->input->post('landmark'),
'rent' => $this->input->post('rent'),
'floor' => $this->input->post('floor'),
'total_floor' => $this->input->post('total_floor'),
'degree' => $this->input->post('degree'),
'check_time' => $this->input->post('check_time'),
'nearline' => $this->input->post('nearline'),
'filenum' => $this->input->post('filenum'),
'create_time' => date('y-m-d h:i:s',time()),
'update_time' => date('y-m-d h:i:s',time()),
);
$this->db->insert('img_records', $data);
//返回上次insert的ID
return $this->db->insert_id();
}
public function delete($id)
{
$this->db->where('id', $id);
$this->db->delete('img_records');
}
}
2 changes: 1 addition & 1 deletion application/models/login_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function checkUser($slug = FALSE){
return FALSE;
}

$query = $this->db->get_where('users', array('slug' => $slug));
//$query = $this->db->get_where('users', array('slug' => $slug));
return $query->row_array();
}
}
Loading