0

複数のファイルをアップロードするコードが必要です。

例えば:

Koala.jpg
Penguins.jpg
Jellyfish.jpg

ユーザーが画像の新しい名前を設定できる入力テキストがあります。

ユーザーは画像をアップロードし、新しい画像名の入力テキストは「動物」です。

今、私が欲しいのは、これがアップロードされたときの出力は、Animals1.jpg、Animals2.jpg、Animals3.jpg である必要があります。

問題は、これらの画像をすべてアップロードしようとしたときに、画像が 1 つしかアップロードされないことです。

私は調査を行い、プログラムにいくつかのコードを適用しようとしましたが、まだ機能していません。

コントローラ

public function do_upload() { 
    $config = array(
        'image_library' => 'gd2',
        'file_name'     => $this->input->post('finame'),
        'upload_path'   => './public/img/uploads',
        'upload_url'    => base_url().'public/img/uploads',
        'allowed_types' => 'gif|jpg|jpeg',
        'max_size'      => '1024KB',
        'max_width'     => '1024',
        'max_height'    => '768',
        'maintain_ratio'=> TRUE,
        'overwrite'     => false,
    );
    $this->load->library('upload', $config);
    if (!$this->upload->do_upload()) {
        $error_msg = "<div class='alert alert-error'>".$this->upload->display_errors()."</div>";
        $error = array('error' => $error_msg);
    } 
    else {
        $upload_data = $this->upload->data();
        $data['thumbnail_name'] = $upload_data['raw_name']. '_thumb' .$upload_data['file_ext'];
        $file_array = array(
            'image'         => $data['thumbnail_name'],
            'image_name'    => $upload_data['file_name'],
            //'description'   => "",
            'date_created'  => date('Y-m-d H:i:s', now()),
            'date_modified' => date('Y-m-d H:i:s', now()),
            'author'        => $this->session->userdata('username'),
            'size'          => $upload_data['file_size'],
            'type'          => $upload_data['image_type'],
            'width'         => $upload_data['image_width'],
            'height'        => $upload_data['image_height'],
            //'document_name' => $field,
            //'department'    => $field2,
            //'notes'         => "",
        );
        $this->session->set_userdata('image_print', $file_array);
        $this->load->database();
        $this->db->insert('tbl_image', $file_array);
        $data = array('upload_data' => $this->upload->data());
        $user_level['records']=$this->user_model->get_records();
        $this->load->view('v_dashboard/page/header_view', $user_level);
        $this->load->view('v_document/upload/upload_result_view', $data);
        $this->load->view('v_dashboard/page/footer_view');
    }
}

HTMLにこれがあります

<label for="file"><strong>Select File To Upload:</strong></label>
<input type="file" name="userfile[]" multiple class="btn transcolor btn-file"/>
<br/><br/>

ところで、データベースで BLOB を使用しています。

このリンクを参照してみました

エリスラブ

GitHub

スタックオーバーフロー

スタックオーバーフロー

CodingLikeASir

4

1 に答える 1

0

アップロードされた画像ファイルの数まで for ループを実行する必要があります。

このような:

for ($i=0; $i < count($_FILES['userfile']['name']); $i++)
{ 
  // function to add the image name one by one into database.
}
于 2014-11-10T10:04:12.007 に答える