2016-07-04 7 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

ようこそ。 [どうすればよい質問をしますか?](http://stackoverflow.com/help/how-to-ask)を見て、あなたの質問を改善してください。 _間違っていますか?_はSOのための質問のようなものではありません。 –

答えて

0

にはpathというキーがありませんので、変数は定義されていません。スクリプトはuploads/(ディレクトリ全体)を削除しようとします。

+0

どうすればいいですか?なぜそれがうまくいかないのかわかりません。 –

+0

'print_r($ _ POST)'と 'print_r($ _ FILES)'を試して、 '$ _FILES'配列で探すべき' path'キーchqnces qreを探してください – kartsims

関連する問題