开发者

$_FILES data is always null

开发者 https://www.devze.com 2023-02-19 09:09 出处:网络
I\'m trying to post a PNG image. Here is my code. <form ac开发者_JAVA技巧tion=\"http://killprashanth.res.cmu.edu/index.php/main/post\"enctype=\"multipart/form-data\" method=\"post\" accept-charset

I'm trying to post a PNG image. Here is my code.

<form ac开发者_JAVA技巧tion="http://killprashanth.res.cmu.edu/index.php/main/post"  enctype="multipart/form-data" method="post" accept-charset="utf-8"> 
<div class="hidden"> 
 <input type="hidden" name="userid" value="" /> 
 <input type="hidden" name="thread" value="" /> 
</div>
<label for="text">Message text:</label>
<textarea name="text" cols="90" rows="12" ></textarea><br>
<table>
 <tr>
  <td style="width: 40%;">
   <label for="file">Image (optional):</label>
   <input type="file" name="file" value=""  />
  </td>
  <td style="width: 60%;">
   <input type="submit" name="submit" value="send" onclick="reload()" />
  </td>
 </tr>
</table>
</form>

and

public function post()
{
        move_uploaded_file($_FILES["file"]["tmp_name"], '/uploads'.$_FILES["file"]["name"]);

        $data = array(
                'userid' => $_POST['userid'],
                'thread' => $_POST['thread'],
                'text' => $_POST['text'],
                'image' => $_FILES["file"]["name"]
        );

        $this->db->insert('messages', $data);
}

In my database, everything works except image (a varchar) is always NULL.


Try removing:

onclick="reload()"

See if it works now. This may be breaking the file upload (it runs "reload" before the form is submitted).

If you want to reload the page instead of actually GOING to the posted page, you may want to look into POSTing through AJAX.

0

精彩评论

暂无评论...
验证码 换一张
取 消