1

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.

Controller:

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);

Model:

    function update($gebruiker)
    {
        $this->db->where('id', $gebruiker->id);
        $this->db->update('gebruiker', $gebruiker);
    }

View:

 <?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(); ?>

Error:

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

Thanks,

SAVe
  • 814
  • 6
  • 22
arnekick
  • 43
  • 7

1 Answers1

0

$_FILES and $_POST vars are 2 different things.

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

should be:

$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.

Alex
  • 9,215
  • 8
  • 39
  • 82