0

codeigniterで画像をアップロードするときに問題が発生するため、次のような画像をアップロードするコントローラーがあります:-

 public function index()
{
    $this->load->model('blog');
    $type = "text";
    if (isset($_POST['post'])) {
        if (isset($_POST['type']) && $_POST['type'] == "image") {
            $type = "image";
        }
        if (strlen($_FILES['inputUpProfile']['name']) > 0) {
            $config['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '2048';
            $config['encrypt_name'] = true;
            $this->load->library('upload', $config);
            if (!$this->upload->do_upload('inputUpProfile')) {
                $error = $this->upload->display_errors();
                if (is_array($error)) {
                    foreach ($error as $er) {
                        $this->errors[] = $er;
                    }
                } else {
                    $this->errors[] = $error;
                }
            } else {
                $updata = $this->upload->data();
                $imagePath = './uploads/' . $eventpic;
                if (file_exists($imagePath)) {
                    @unlink($imagePath);
                }
                $eventpic = $updata['raw_name'] . $updata['file_ext'];
            }
        }
        $result = $this->blog->addPost($_SESSION['user_id'], $type, $this->input->post('post'), $eventpic);
    }

    $result = $this->blog->getPosts($_SESSION['user_id'], 0, 10);
    $this->template->build("home_view", array("response" => $result));
}

ビューは次のようになります:-

<div class="textstatus">
    <input id="inputUpProfile" name="inputUpProfile"
           class="inputUpProfile hidefile" type="file"/>
    <input type="button" id="PicUpProfile" class="sentpic" value="addpic">
    <input name="post" type="text" id="text" placeholder="message ...">
    <input type="submit" id="sent" value="Send">
</div>
</form>
</div>

自分のサイトに画像をアップロードすると、次のようなエラーが表示されます:-

Severity: Notice

Message: Undefined index: inputUpProfile

Filename: controllers/home.php

Line Number: 47

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: eventpic

Filename: controllers/home.php

Line Number: 74

A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at D:\AppServ\www\sys\system\core\Exceptions.php:185)

Filename: core/Common.php

Line Number: 442

私のコードの問題はどこにありますか。

/ * ** * ** * ** * ** * ***

編集 :-

Array ( [upload_data] => Array ( [file_name] => 67429_133961013479569_306349156_n3.jpg [file_type] => image/jpeg [file_path] => D:/AppServ/www/d5n/rashaqa2/uploads/ [full_path] => D:/AppServ/www/d5n/rashaqa2/uploads/67429_133961013479569_306349156_n3.jpg [raw_name] => 67429_133961013479569_306349156_n3 [orig_name] => 67429_133961013479569_306349156_n.jpg [client_name] => 67429_133961013479569_306349156_n.jpg [file_ext] => .jpg [file_size] => 34.05 [is_image] => 1 [image_width] => 720 [image_height] => 540 [image_type] => jpeg [image_size_str] => width="720" height="540" ) ) 

DBに保存するには、この配列[file_name]から必要です。これを読み取るにはどうすればよいですか。

4

1 に答える 1

1
  if($_FILES['nameofinputtype']['error'] == UPLOAD_ERR_OK)
    {
       // A file was uploaded

            $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);
            $imagen = $this->upload->do_upload();
    }
于 2013-08-20T04:55:37.740 に答える