Welcome Guest, Not a member yet? Register   Sign In
Image not uploading!
#1
Rainbow 

PHP Code:
<div class="custom-file">
 
               <input name="image" type="file" class="custom-file-input"  id="customFile">
 
               <label class="custom-file-label" for="customFile">Choose Image</label>
 
           </div

PHP Code:
public function create_blog() 
    {
        if (!isset(
$_POST['submit']))
        {
            
$this->load->view('temp/header-short');
            
$this->load->view('admin/create_blog');
            
$this->load->view('temp/footer');
        }
        else {
            
$image $_POST['image'];
            
$head $_POST['head'];
            
$body $_POST['body'];
            
$footer $_POST['footer'];

            
$config['upload_path'] = './src/img/blog';
            
$config['upload_path'] = './uploads/';
            
$config['allowed_types'] = 'gif|jpg|png';
            
$config['max_size'] = 10000;
            
$config['max_width'] = 4000;
            
$config['max_height'] = 4000;

            
$this->load->library('upload'$config);

            if ( ! 
$this->upload->do_upload('image'))
            {
                    
$error = array('error' => $this->upload->display_errors());
                    
$this->load->view('temp/header-short');
                    
$this->load->view('admin/create_blog'$error);
                    
$this->load->view('temp/footer');
            }
            else
            {
                    
$data = array('upload_data' => $this->upload->data());

                    
$this->load->view('upload_success'$data);
            }
        }
    } 

Error message is 'You did not upload the file'.

I cannot see anything wrong.
Reply
#2

Hello,
if you can post the form code also, so
1) you have to add <form enctype="multipart/form-data" , the entype on form open tag
2)ideally try to use the example from CI toturial input
3) print the upload error so you can see whats going on
4) dont forget that you have max size 10mb but the server maybe is on 2mb , so you have to check the server too!

Thas all Smile
Reply
#3

Did you include multipart in the form declaration (in the view)?
If you (auto)load the form helper, you can do it like this:
PHP Code:
<?php echo form_open_multipart('blogs/create_blog');?>

Also check whether you set the right permissions for the folder.
Reply
#4

Now I am getting an error saying that The upload path does not appear to be valid.

public function create_blog()
{
if (!isset($_POST['submit']))
{
$this->load->view('temp/header-short');
$this->load->view('admin/create_blog');
$this->load->view('temp/footer');
}
else {

$head = $_POST['head'];
$body = $_POST['body'];
$footer = $_POST['footer'];

$config['upload_path'] = base_url('/src/img/blog');
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 10000;
$config['max_width'] = 4000;
$config['max_height'] = 4000;

$this->upload->initialize($config);

if ( ! $this->upload->do_upload('image'))
{
$error = array('message' => $this->upload->display_errors());
$this->load->view('temp/header-short');
$this->load->view('admin/create_blog', $error);
$this->load->view('temp/footer');
}
else
{
$data = array('message' => $this->upload->data());
$this->load->view('temp/header-short');
$this->load->view('admin/create_blog', $data);
$this->load->view('temp/footer');
}
}
}


<div class="container" style="margin-top: 4rem; margin-bottom: 4rem;">
<div class="row">
<?php
$attributes = array(
'style' => 'width: 70%; margin: auto;'
);
echo form_open_multipart('admin/create_blog', $attributes);
?>
<?php if (isset($message)) { echo "<div class='alert alert-warning' role='alert'>".$message."</div>"; } ?>
<h1>Blog Creation</h1><br>
<div class="form-group">
<label for="exampleFormControlFile1">Example file input</label>
<input name="image" type="file" class="form-control-file" id="exampleFormControlFile1">
</div><hr>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Title</span>
</div>
<input name="head" type="text" class="form-control">
</div>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text">Body</span>
</div>
<textarea name="body" class="form-control"></textarea>
</div><br>
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Written By</span>
</div>
<input name="footer" type="text" class="form-control">
</div>
<div style="float: right;">
<button name="submit" type="submit" class="btn btn-success">Submit</button>
<button name="cancel" type="submit" formaction="<?php echo base_url('admin') ?>" class="btn btn-warning">Cancel</button>
</div>
</form>
</div>
</div>
Reply




Theme © iAndrew 2016 - Forum software by © MyBB