2016-07-04 43 views
0

我有一個關於「取消鏈接」更新的問題。 error message after post更新Iage使用取消鏈接CodeIgniter

控制器

控制器:

<?php 
defined('BASEPATH') OR exit('No direct script access allowed'); 

class Picture_controller extends CI_Controller 
{ 

    public function index(){ 
     $result = $this->db->query("SELECT * FROM img"); 
     $this->load->view('picture/index', array('data'=>$result)); 
    } 

    public function form(){ 
     $this->load->view('picture/form', array('error' => '')); 
    } 

    public function edit($id){ 
     $data = $this->db->query("SELECT * FROM img WHERE id = '{$id}' "); 
     $row = $data->row(); 
     $this->load->view('picture/edit',array('r'=>$row)); 
    } 

    public function do_update(){  
     $id = $this->input->post('id'); 
     $path = $this->input->post('path'); 
     if (isset($_FILES['userfile']['name']) && !empty($_FILES['userfile']['name'])) 
     { 
      if(unlink('uploads/'.$path)) 
      { 
       $config['upload_path'] = './uploads'; 
       $config['allowed_types'] = 'gif|jpg|png'; 
       $config['max_size'] = 20000000; 
       $config['max_width'] = 1024; 
       $config['max_height'] = 768; 
       $config['encrypt_name'] = TRUE; 

       //miantso library 
       $this->load->library('upload',$config); 

       if(!$this->upload->do_upload()) 
       { 
        $error = array('error' => $this->upload->display_errors()); 
        $this->load->view('picture/form', $error); 
       } 
       else 
       { 
        $data = $this->upload->data(); 
        // var_dump($data); 
        $data_array = array(
         'file_name' => $data['file_name'], 
         'original_name' => $data['orig_name'], 
         'file_size' => $data['file_size'], 
         'file_ext' => $data['file_ext'], 
         'full_path' => $data['full_path'] 
         ); 
       $this->db->where('id',$id); 
       $this->db->update('img',$data_array); 
       redirect('Picture_controller/index'); 
       } 
      } 
     } 
     else 
     { 
      redirect('Picture_controller/index'); 
     } 
    } 

    public function do_upload() 
    { 

     $config['upload_path'] = './uploads'; 
     $config['allowed_types'] = 'gif|jpg|png'; 
     $config['max_size'] = 20000000; 
     $config['max_width'] = 1024; 
     $config['max_height'] = 768; 
     $config['encrypt_name'] = TRUE; 


    //miantso library 
    $this->load->library('upload',$config); 

    if(!$this->upload->do_upload()) 
    { 
     $error = array('error' => $this->upload->display_errors()); 
     $this->load->view('picture/form', $error); 
    } 
    else 
    { 
     $data = $this->upload->data(); 
     // var_dump($data); 
     $data_array = array(
      'file_name' => $data['file_name'], 
      'original_name' => $data['orig_name'], 
      'file_size' => $data['file_size'], 
      'file_ext' => $data['file_ext'], 
      'full_path' => $data['full_path'] 
      ); 
    $this->db->insert('img',$data_array); 
    redirect('Picture_controller/index'); 
    } 
} 

} 
?> 

有什麼不對?你能幫我嗎?

+0

歡迎來到SO。請看看[我如何問一個好問題?](http://stackoverflow.com/help/how-to-ask)並改進您的問題。 _什麼是錯的?_不是那種問題。 –

回答

0

$path變量未定義(我猜$_POST沒有path鍵),因此腳本嘗試刪除uploads/(整個目錄)。

+0

我該怎麼辦?我不知道爲什麼它不起作用 –

+0

嘗試'print_r($ _ POST)'和'print_r($ _ FILES)'並查找'path'鍵,查詢qre,你應該在'$ _FILES'數組中尋找它 – kartsims