为了账号安全,请及时绑定邮箱和手机立即绑定

MySQL在php中插入图片post函数返回0

MySQL在php中插入图片post函数返回0

PHP
小唯快跑啊 2021-07-05 17:27:32
我正在尝试为我的用户导入个人资料图片并将其以 blob 格式插入到数据库中。但是当我运行代码并选择一个图像时,我得到 file_get_contents() 不能为空错误我已经尝试了许多与此问题相关的其他帖子的解决方案,但都没有奏效。控制器: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: WarningMessage: file_get_contents(): Filename cannot be emptyFilename: controllers/Home.phpLine Number: 147Backtrace:File: /home/arne/Desktop/WebApplication/CodeIgniter/application/controllers/Home.phpLine: 147Function: file_get_contentsFile: /home/arne/Desktop/WebApplication/CodeIgniter/index.phpLine: 315Function: require_onceI except an image to be in my database but the post isn't working谢谢,
查看完整描述

1 回答

?
人到中年有点甜

TA贡献1895条经验 获得超7个赞

$_FILES$_POSTvars 是两种不同的东西。

$foto = $this->input->post($_FILES['profielfoto']['tmp_name']);

应该:

$foto = $_FILES['profielfoto']['tmp_name'];

请注意,这并没有考虑到错误,因此您应该理所当然地检查一下。


查看完整回答
反对 回复 2021-07-09
  • 1 回答
  • 0 关注
  • 176 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信