我正在尝试发布PNG图像。这是我的代码。
<form action="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>
和
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);
}
在我的数据库,一切正常,除了图像(VARCHAR)始终是NULL。
该文件是否上传到您的上传目录? – GWW 2011-03-24 23:04:54
你检查了整个数组:print_r($ _ FILES)? – Osw 2011-03-24 23:08:26
不要使用用户提供的文件名写入文件系统。这里有一个令人讨厌的目录遍历安全漏洞,但还有很多其他问题需要解决。将文件存储在自动生成的已知好名称(例如'uploadid-17236478.png')下。 – bobince 2011-03-24 23:17:23