• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Accessing $_FILES without having to upload a file

#2
[eluser]gtech[/eluser]
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.
Code:
//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;
     }    
     else
     {
         $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);
         fclose($fp);
         // delete file
         unlink($tmpName);
         // 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.


Messages In This Thread
Accessing $_FILES without having to upload a file - by El Forum - 06-09-2008, 08:54 AM
Accessing $_FILES without having to upload a file - by El Forum - 06-09-2008, 04:55 PM
Accessing $_FILES without having to upload a file - by El Forum - 06-10-2008, 04:01 AM
Accessing $_FILES without having to upload a file - by El Forum - 07-22-2008, 04:33 AM
Accessing $_FILES without having to upload a file - by El Forum - 08-02-2010, 09:26 PM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.