簡體   English   中英

Codeigniter:您沒有選擇要上傳的文件

[英]Codeigniter: You did not select a file to upload

我正在嘗試使用codeigniter上載圖像,無論我如何不斷收到“您未選擇要上載的文件”錯誤。

這是我的控制器:

<?php
    class Post extends CI_Controller {
        function __construct(){
            parent::__construct();
        }

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

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

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

            if (!$this->upload->do_upload('userfile'))
            {
                $error = array('error' => $this->upload->display_errors());
                echo json_encode($error);
            }
            else
            {
                $file_data = array('upload_data' => $this->upload->data());
                $data['img'] = base_url().'/images/'.$file_data['file_name'];
                echo json_encode($data);
            }
    }
    }
?>

這是我的觀點:

<html lang="en">
    <head>
        <meta charset="utf-8"/>
        <meta http-equiv="X-UA-Compatible" content="IE-9"/>
    </head>
    <body>

    <form action="" method="POST" enctype="multipart/form-data" >
    Select File To Upload:<br />
    <input type="file" name="userfile"  />
    <br /><br />
    <input type="submit" name="submit" value="Upload" class="btn btn-success" />
</form>
    </body>
</html>

誰能幫我解決這個問題? 感謝您的幫助:)

根據代碼索引功能加載表單,在哪個函數上提交表單,而不是在上一頁函數上提交

我找到了解決方案

我按照本教程進行了修復。

http://www.formget.com/codeigniter-upload-image/

感謝所有回答我的問題的人:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM