Welcome Guest, Not a member yet? Register   Sign In
Accessing $_FILES without having to upload a file

Hi all.

I'm a real n00b when it comes to CodeIgniter, as I've just started my first project in it a few days ago.

There is an issue that I can't seem resolve when it comes to uploading files, and reading the data of the uploaded file.

For this specific project, I'm storing my images as a LONGBLOB in a database. Because of this, I don't really need to store the file in a permanent location on the server when uploading it. All I need is access to the uploaded file's details, and I'll then insert the raw data into the LONGBLOB field.

Now my real question is, is there functionality native to CI that will allow for this, or am I going to have to write my own class to handle these types of uploads?

Any help whatsoever would really be appreciated.


I do a similar thing to upload into a MEDIUMBLOB, but couldn't get around it without uploading a file.. instead I delete (unlink) the file, after I gathered the content.

Step 1: I use the upload library to upload the file (read the documentation)
Step 2: after the call to do_upload() I read in the file, get the content, delete the file and then insert it into the database.
//read upload library documentation
     $config['allowed_types'] = 'gif|jpg|png|mpg|wmv|mp3|wav';
     $config['max_size']    = '16777215';
     $config['max_width']  = '3000';
     $config['max_height']  = '3000';

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

     if ( ! $this->upload->do_upload())
         $error = $this->upload->display_errors();
         $ret = array();
         $ret['ErrorType'] = 2;
         $ret['ErrorMessage'] = $error;
         return $ret;
         $data = array('upload_data' => $this->upload->data());
         $tmpName  = $data['upload_data']['full_path'];
         $fileSize = $data['upload_data']['file_size'];

         $fp      = fopen($tmpName, 'r');
         $content = fread($fp, filesize($tmpName));
         $content = addslashes($content);
         // delete file
         // now just insert $content into the database LONGBLOB. (remove slashes when reading in)

you have to ensure you database can handle longblobs as I had to change the mysql config to cope with this.

Awesomeness! Thanks for the suggestion. I was playing around with solutions yesterday, and I came across a very similar idea.

The help is appreciated Smile

thanks very helpful

well it seems that actually I have to do this also. lucky i dont use the longblob so no more config i have to do..

Theme © iAndrew 2016 - Forum software by © MyBB