【问题标题】:MySQL Insert image in php the post functions return 0MySQL 在 php 中插入图像后函数返回 0
【发布时间】:2019-10-11 15:33:14
【问题描述】:

我正在尝试为我的用户导入个人资料图片并以 blob 格式将其插入数据库。但是当我运行代码并选择图像时,我得到 file_get_contents() cannot be empty 错误

我尝试了其他帖子中与此问题相关的许多解决方案,但都没有奏效。

控制器:

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

谢谢,

【问题讨论】:

标签: php mysql codeigniter blob


【解决方案1】:

$_FILES$_POST 变量是两个不同的东西。

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

应该是:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-05
    • 2012-03-09
    • 2012-09-12
    • 1970-01-01
    • 2014-06-19
    • 1970-01-01
    • 2014-01-13
    • 1970-01-01
    相关资源
    最近更新 更多