dounaoji2054 2017-03-13 10:04
浏览 22
已采纳

图像文件空了

I have created a script to upload the image with text but the problem is that when we post the data and upload the image the file is coming empty I do not know why the file is coming empty can anyone help me out to get the correct file

This is my ajax script

$(document).ready(function(e) {
$("#post").on('submit', (function(e) {
    $("#load").show();

    var form = this;
    var formData = new FormData(this);
    alert(formData);
    formData.append('post_dt', $("#contentbox").html());

    $.ajax({
        url         : "http://domainname.com/demo/forums/post_forum",
        type        : "POST",
        data        : formData,
        contentType : false,
        cache       : false,
        processData : false,
        success     : function(data) {
            $("#data_update").prepend($(data).fadeIn('slow'));
            $("#contentbox").empty();
            form.reset();
        },
        complete: function() {
            $("#load").hide();
        }
    });
}));
});

This the html form which is being created

<form method="POST" action="" id="post" enctype="multipart/form-data" onsubmit="return false;">
                <ul>
                    <li>
                        <i class="fa fa-photo"></i> Upload A Photo / Document
                        <input type="file" name="image" />
                    </li>
                </ul>
                <div id='display'></div>
                <div id="contentbox" contenteditable="true" name="post_dt">
                </div>

                <input type="submit" id="sb_art" class="btn_v2" value="Start Discussion" />
            </form>

My php script which I have created within the controller

public function post_forum() {
    $config['upload_path']   = './assets/uploads/';
    $config['allowed_types'] = 'gif|jpg|png';
    $config['max_size']      = 3000;
    $this->load->library('upload', $config);

    if(!empty($this->input->post('image'))) {
        if (!$this->upload->do_upload('image')) {
            $error = array('error' => $this->upload->display_errors());
        } else {
            $dt = $this->upload->data();
            $file = $dt['file_name'];
        }
    } else {
        $file = 'Filename.jpg';
    }
    $word_dta    = $this->input->post('post_dt');
    $time_posted = time();
    $user_id     = $this->basic_model->is_login($this);

    $data_upload = array(
        'upload_document' => $file,
        'discussion'      => $word_dta,
        'user_id'         => $user_id,
        'time_posted'     => $time_posted,
        'status'          => 'Posted'
    );

    $post_id = $this->basic_model->insertRecord($data_upload, 'forums');

    $data = array(
        'file_name'   => $file,
        'data'        => $word_dta,
        'time_posted' => $time_posted,
        'post_id'     => $post_id,
        'name'        => $this->basic_model->getUserData(),
        'command'     => 'Submit Post'
    );

    $this->load->view('forum/includes/get_data', $data);
}
  • 写回答

3条回答 默认 最新

  • doushichi3678 2017-03-15 09:11
    关注

    I have sorted out my issue I was making a mistake within the controller which was my mistak so I have resolved my issues take care

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 被蓝屏搞吐了,有偿求帮解答,Ai回复直接拉黑
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并