Skip to content
This repository has been archived by the owner on Jul 14, 2021. It is now read-only.

Need a Good CI Bonfire File Uploader Example #1310

Open
OAVHomeAdmin opened this issue Oct 26, 2018 · 2 comments
Open

Need a Good CI Bonfire File Uploader Example #1310

OAVHomeAdmin opened this issue Oct 26, 2018 · 2 comments

Comments

@OAVHomeAdmin
Copy link

I have been testing to get a good file uploader coded with the ability to change the Upload Destination using a Form Select Input and a MySQL Script, but I can't even find a good example for a File Uploader to start off with.

Can anyone provide a good example of a File Uploader for CI Bonfire?

@Reconix
Copy link
Contributor

Reconix commented Dec 20, 2018

Was there something the upload library couldn't do ?

@cosmomathieu
Copy link

This should get you started!

<?php 

$file_element_name = 'file';
$upload_path = FCPATH . 'uploads/';

$config['upload_path'] = $upload_path;
$config['allowed_types'] = 'csv|xls|xlsx'; // You allowed file extensions 
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = false;

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

if (!$this->upload->do_upload($file_element_name))
{
    $status = 'error';
    $msg = $this->upload->display_errors('', '');
}
else
{
    $data = $this->upload->data();
    $fileName = $data['file_name'];
    $file = $upload_path . $fileName;
    // Dome something with $file, like get contents, etc. 
}
@unlink($_FILES[$file_element_name]);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants