3

ユーザー登録できるページがあります。彼はその過程でプロフィール写真をアップロードします。サイズを制限したいのですが、$config['maxsize'] を除いて、codeigniter のドキュメントにはあまり重点が置かれていません。以下を試しましたが、メッセージが表示されません。テスト用にサイズを 10 (KB) に設定しました。メッセージを自分のビューに伝えるために、何らかの方法で処理する必要がありますか?

public function add_user()
    {


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

        $this->load->library('upload', $config);
        $fullImagePath;
        if (isset($_FILES['userfile']) && !empty($_FILES['userfile']['name']))
          {
          if ($this->upload->do_upload('userfile'))
          {
            // set a $_POST value for 'image' that we can use later
...

ちなみに、このコードは私のモデルにあります。

4

4 に答える 4

4

@Chetan Wadhwa、

サイズがバイト単位であることは確かですか(KB単位ではありません)。codeigniter のドキュメントを参照してください: http://www.codeigniter.com/user_guide/libraries/file_uploading.html (KB 単位である必要があります)。

于 2014-05-22T13:32:42.420 に答える
1

このサイズは KB 単位ではなくバイト単位であるため、10KB の場合は (10*1024) バイトまたは「10240」と書き込む必要があります。

于 2013-08-29T09:45:01.323 に答える
0
<?php

class upload extends CI_Controller {

function __construct()
{
    parent::__construct();
    $this->load->helper(array('form', 'url'));
}

function index()
{
    $this->load->view('upload_form', array('error' => ' ' ));
}

function do_upload()
{
    $config['upload_path'] = './uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size'] = '100';
    $config['max_width']  = '1024';
    $config['max_height']  = '768';


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

    if ( ! $this->upload->do_upload())
    {
        $error = array('error' => $this->upload->display_errors());

        $this->load->view('upload_form', $error);
    }
    else
    {
        $data = array('upload_data' => $this->upload->data());

        $this->load->view('upload_success', $data);
    }

}
}
?>
于 2013-04-25T07:42:57.833 に答える