2016-07-04 2 views
0

У меня возникла проблема с обновлением «unlink». error message after postОбновление с использованием unlink 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) и улучшите свой вопрос. _Что не так? _ - это не тот вопрос, для которого нужен SO. –

ответ

0

$path Переменная не определена (я думаю $_POST не имеет path ключ), поэтому сценарий пытается удалить uploads/ (весь каталог).

+0

Что мне делать? Я не знаю, почему это не работает. –

+0

попробуйте 'print_r ($ _ POST)' и 'print_r ($ _ FILES)' и ищите ключ 'path', chqnces qre, вы должны искать его в массиве' $ _FILES' – kartsims

Смежные вопросы