Welcome Guest, Not a member yet? Register   Sign In
File type returning NULL - Did actually work but I don't know what I have done. Help!

Before the breakdown the view was returning a string and storing that string in a database. Since its my first time trying a project, a run into a problem where previously it worked, and then after it just decided to stop working. 

The Error Message: 
A PHP Error was encountered
Severity: Notice
Message: Undefined index: picture
Filename: models/Horse_model.php
Line Number: 23
File: C:\xampp\htdocs\rusaliite\application\models\Horse_model.php
Line: 23
Function: _error_handler

File: C:\xampp\htdocs\rusaliite\application\controllers\Horse_controller.php
Line: 27
Function: create

File: C:\xampp\htdocs\rusaliite\index.php
Line: 315
Function: require_once

The View:
<div id="body">
    <?php echo validation_errors(); ?>
        <?php echo form_open_multipart('horse_controller/create'); ?>
            <form style="width: 30%;">
                <div class="form-group">
                    <input name="name" class="form-control" maxlength="20">
                <div class="form-group">
                    <label>Bulgarian Name</label>
                    <input name="name_bulgarian" class="form-control" maxlength="20">
                <div class="form-group">
                    <input name="sex" class="form-control" maxlength="1" placeholder="M or F">
                <div class="form-group">
                    <label>Stable Number</label>
                    <input name="stable_no" class="form-control" maxlength="2" type="number">
                <div class="form-group">
                    <input name="picture" type="file" class="form-control-file">
                <button type="submit" method="POST" class="btn btn-primary">Submit</button>

The Controller:
public function create()
        if($_SERVER['REQUEST_METHOD'] == 'POST')
            // $config['upload_path']          = './uploads/';
            // $config['allowed_types']        = '';
            // $config['max_size']             = 0;
            // $config['max_width']            = 0;
            // $config['max_height']           = 0;
            // $this->load->library('upload', $config);
            // $this->upload->do_upload('photo');

            $data['horses'] = $this->Horse_model->create();


The Model:
   public function create()
       $this->name             = $_POST['name'];
       $this->name_bulgarian   = $_POST['name_bulgarian'];
       $this->sex              = $_POST['sex'];
       $this->stable_no        = $_POST['stable_no'];
       $this->picture          = $_POST['picture'];

       $this->db->insert('horse', $this);

Uploaded files handle differently from uploaded form data.

You have form_open_multipart function call followed by another form tag, that will generate two forms inside each other and submit will only work in inner form, so that might cause some issues.

Also, all type="file" go into $_FILES instead of $_POST variable.

More details on how to handle uploads with CodeIgniter at https://www.codeigniter.com/userguide3/l...ading.html
Also, for raw PHP approach, you can read up how it works here http://php.net/manual/en/features.file-u...method.php

Hey I wrote before but I don't see it, I'll say it again just incase there was some problem. 

I had the thing working, it was returning the string of the file, which I want to store in the database and then I can use this to reference the picture I want to use in the file. 

The whole thing was totally working now, its not. Totally head dead, after looking at it over and over again.

The $_File works but it doesn't return the string value, which I want to store in the database.

Hey, thanks, so looking further into it I used $_POST['file]['name]. I have total brain drain from this little problem, I have no idea why before it worked and it decided to stop.

Theme © iAndrew 2016 - Forum software by © MyBB