MySQL在PHP中插入图像后功能返回0 [英] MySQL Insert image in php the post functions return 0
本文介绍了MySQL在PHP中插入图像后功能返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为我的用户导入个人资料图片,并将其以blob格式插入数据库中.但是当我运行代码并选择图像时,我得到file_get_contents()不能为空错误
Im trying to import a profile picture for my users and insert it in the database in blob format. But when im running the code and i select an image i get file_get_contents() cannot be empty error
我尝试了其他帖子中与该问题有关的许多解决方案,但均无济于事.
I have tried many solutions from other post related to this problem none of them worked.
控制器:
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(); ?>
错误:
Severity: Warning
Message: file_get_contents(): Filename cannot be empty
Filename: controllers/Home.php
Line Number: 147
Backtrace:
File: /home/arne/Desktop/WebApplication/CodeIgniter/application/controllers/Home.php
Line: 147
Function: file_get_contents
File: /home/arne/Desktop/WebApplication/CodeIgniter/index.php
Line: 315
Function: require_once
I except an image to be in my database but the post isn't working
谢谢
推荐答案
$_FILES
和$_POST
var是2种不同的东西.
$_FILES
and $_POST
vars are 2 different things.
$foto = $this->input->post($_FILES['profielfoto']['tmp_name']);
应该是:
$foto = $_FILES['profielfoto']['tmp_name'];
,请注意,这不会考虑到错误,因此您当然应该检查一下.
and please note this does not take in to account errors so you should probably check for that as a matter of course.
这篇关于MySQL在PHP中插入图像后功能返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文