php中的MySQL插入图像post函数返回0
我正在尝试为我的用户导入一个配置文件图片,并将其以blob格式插入数据库。但是当我运行代码并选择图像时,我得到的文件\u get\u contents()不能为空错误 我已经尝试了许多其他与这个问题相关的解决方案,但都没有成功 控制器:php中的MySQL插入图像post函数返回0,php,mysql,codeigniter,blob,Php,Mysql,Codeigniter,Blob,我正在尝试为我的用户导入一个配置文件图片,并将其以blob格式插入数据库。但是当我运行代码并选择图像时,我得到的文件\u get\u contents()不能为空错误 我已经尝试了许多其他与这个问题相关的解决方案,但都没有成功 控制器: public function wijzigen() { $foto = $this->input->post($_FILES['profielfoto']['tmp_name']); $fotoContent = addslash
public function wijzigen()
{
$foto = $this->input->post($_FILES['profielfoto']['tmp_name']);
$fotoContent = addslashes(file_get_contents($foto));
$id = $this->session->userdata('id');
$gebruiker = new stdClass();
$gebruiker->id = $id;
$gebruiker->profileImage = $fotoContent;
$this->load->model('gebruiker_model');
$this->gebruiker_model->update($gebruiker);
function update($gebruiker)
{
$this->db->where('id', $gebruiker->id);
$this->db->update('gebruiker', $gebruiker);
}
<?php
$attributes = array('name' => 'mijnFormulier', 'enctype'=>'multipart/form-data', 'method'=>'post', 'accept-charset'=>'utf-8');
echo form_open('Home/wijzigen', $attributes);
?>
<table>
<tr>
<td><?php echo form_label('Profiel Foto:', 'profielfoto'); ?></td>
<td><input type="file" name="profielfoto" id="profielfoto" required accept=".png"/></td>
</tr>
<tr>
<td></td>
<td>
<?php echo form_submit('knop', 'Wijzigen', 'class = "btn btn-login login-formcontrol"'); ?>
</td>
</tr>
</table>
<?php echo form_close(); ?>
型号:
public function wijzigen()
{
$foto = $this->input->post($_FILES['profielfoto']['tmp_name']);
$fotoContent = addslashes(file_get_contents($foto));
$id = $this->session->userdata('id');
$gebruiker = new stdClass();
$gebruiker->id = $id;
$gebruiker->profileImage = $fotoContent;
$this->load->model('gebruiker_model');
$this->gebruiker_model->update($gebruiker);
function update($gebruiker)
{
$this->db->where('id', $gebruiker->id);
$this->db->update('gebruiker', $gebruiker);
}
<?php
$attributes = array('name' => 'mijnFormulier', 'enctype'=>'multipart/form-data', 'method'=>'post', 'accept-charset'=>'utf-8');
echo form_open('Home/wijzigen', $attributes);
?>
<table>
<tr>
<td><?php echo form_label('Profiel Foto:', 'profielfoto'); ?></td>
<td><input type="file" name="profielfoto" id="profielfoto" required accept=".png"/></td>
</tr>
<tr>
<td></td>
<td>
<?php echo form_submit('knop', 'Wijzigen', 'class = "btn btn-login login-formcontrol"'); ?>
</td>
</tr>
</table>
<?php echo form_close(); ?>
查看:
public function wijzigen()
{
$foto = $this->input->post($_FILES['profielfoto']['tmp_name']);
$fotoContent = addslashes(file_get_contents($foto));
$id = $this->session->userdata('id');
$gebruiker = new stdClass();
$gebruiker->id = $id;
$gebruiker->profileImage = $fotoContent;
$this->load->model('gebruiker_model');
$this->gebruiker_model->update($gebruiker);
function update($gebruiker)
{
$this->db->where('id', $gebruiker->id);
$this->db->update('gebruiker', $gebruiker);
}
<?php
$attributes = array('name' => 'mijnFormulier', 'enctype'=>'multipart/form-data', 'method'=>'post', 'accept-charset'=>'utf-8');
echo form_open('Home/wijzigen', $attributes);
?>
<table>
<tr>
<td><?php echo form_label('Profiel Foto:', 'profielfoto'); ?></td>
<td><input type="file" name="profielfoto" id="profielfoto" required accept=".png"/></td>
</tr>
<tr>
<td></td>
<td>
<?php echo form_submit('knop', 'Wijzigen', 'class = "btn btn-login login-formcontrol"'); ?>
</td>
</tr>
</table>
<?php echo form_close(); ?>
谢谢,
$\u文件和$\u POST
变量是两种不同的东西
$foto = $this->input->post($_FILES['profielfoto']['tmp_name']);
应该是:
$foto = $_FILES['profielfoto']['tmp_name'];
请注意,这并没有考虑到错误,所以您应该理所当然地检查它。$\u文件和$\u POST
变量是两种不同的东西
$foto = $this->input->post($_FILES['profielfoto']['tmp_name']);
应该是:
$foto = $_FILES['profielfoto']['tmp_name'];
请注意,这并没有考虑到错误,因此您应该理所当然地检查它。您的路由是否为此主页/wijzigen
配置?请参阅您的路由是否为此主页/wijzigen
配置?请参阅