0

CodeIgniter ライブラリの読み込みに問題があります。

私はすでに CodeIgniter を使って 3 つの Web サイトを構築しているので、このフレームワークには慣れていると思います。

問題はアップロードライブラリのみです。複数の関数で試しましたが、まだ機能しません。

CodeIgniter の例で試してみました

グーグルでは答えが見つかりません。誰かがそれが何であるか考えていますか?

class Admin extends CI_Controller {

public function __construct(){
    parent::__construct();
    $this->load->library('session');
    $this->load->library('v');
    $this->load->model('admin_model');
}

public function upload_a_thing($set = null){
    $this->load->helper(array('form', 'url'));
    if(!$set){
        $this->load->view('admin/upload_a_thing');
    }else{
        $this->load->library('Upload');
        if (!$this->upload->do_upload('userfile')){
            echo $this->upload->display_errors();
        } else {

            $file = $this->upload->data();
            //          $product = $this->admin_model->get_products($id);
            $newFilePath = $config['upload_path'].'try.jpg';
            $file['file_name'] = str_replace(" ","_",$file['file_name']);
            rename($config['upload_path'].$file['file_name'], $newFilePath);
        }   
    }
}   

CodeIgniter エラー

 Undefined property: Admin::$upload

PHP エラー

Fatal error: Call to a member function do_upload() on a non-object 

Spary用に編集

        $config['upload_path'] = './media/imgs/products/';
        $this->load->library('upload',$config);
        if (!$this->upload->do_upload('userfile')){
            echo $this->upload->display_errors();
        }
4

3 に答える 3

1

フォームが次のようになっている場合:

<input type="file" class="input" name="logo"  />

次に、次のように do_upload() を呼び出します。

 do_upload('logo');

次のようになっている場合:

 <input type="file" class="input" name="userfile" />

次に、次のように呼び出します。

 do_upload();
于 2014-12-05T22:27:06.987 に答える
0

あなたのコード...

$this->load->library('Upload');

ドキュメントのすべての例のようuploadに、 はすべて小文字にする必要があり、ライブラリが読み込まれていない可能性が最も高い理由です。


さらに、$config配列が見つからない場合は、ドキュメントのサンプル コードに従っていません。

$config['upload_path'] = './uploads/';   // <- preferences
$this->load->library('upload', $config); // <- load library and set configuration

また

$this->load->library('upload');         // <- load library

$config['upload_path'] = './uploads/';  // <- preferences
$this->upload->initialize($config);     // <- set configuration

また

// 'upload' library is "auto-loaded"    // <- load library

$config['upload_path'] = './uploads/';  // <- preferences
$this->upload->initialize($config);     // <- set configuration

好みのチャートから、それらはすべてオプションのように見えますが、upload_path...

デフォルト値: なし

説明: アップロードを配置するフォルダーへのパス。フォルダーは書き込み可能である必要があり、パスは絶対パスまたは相対パスにすることができます。

upload_pathデフォルトがなく、構成配列全体が欠落しているため、ファイルがない場合に CodeIgniter がファイルをアップロードする場所をどのように知ることができるかわかりません。

于 2014-12-06T16:11:59.343 に答える