public function action_base64_encode_image()
 {
     if ($_POST) {
         $asciiFormat = Inflector::ascii(Input::post('filename'));
         $webSafeName = Inflector::friendly_title($asciiFormat, '_', true);
         $uploadLocation = 'assets/img/upload/';
         $config = array('auto_process' => 'false', 'path' => DOCROOT . $uploadLocation, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png'), 'new_name' => $webSafeName, 'normalize' => true, 'change_case' => 'lower', 'auto_rename' => false, 'overwrite' => true);
         // process the uploaded files in $_FILES
         Upload::process($config);
         // if there are any valid files
         if (Upload::is_valid()) {
             // save them according to the config
             Upload::save();
             // Grab the file extension
             $uploadedFile = Upload::get_files(0);
             $filename = $webSafeName . '.' . $uploadedFile['extension'];
             $input_file = $uploadedFile['saved_to'] . $uploadedFile['saved_as'];
             $image64Encoded = $this->_base64_encode_image($input_file, $uploadedFile['extension']);
             $asset = Model_Asset::forge(array('name' => $uploadedFile['saved_as'], 'uri' => $uploadLocation, 'type' => $uploadedFile['extension']));
             $asset->save();
             return '<img src="' . $image64Encoded . '" />';
         } else {
             // and process any errors
             foreach (Upload::get_errors() as $key => $file) {
                 // $file is an array with all file information,
                 // $file['errors'] contains an array of all error occurred
                 // each array element is an an array containing 'error' and 'message'
                 //                Session::set_flash('error', $file['errors'] );
                 echo 'Error ' . $key . ' - ';
                 print_r($file['errors']);
                 echo ' <br />';
             }
             die;
         }
     }
     return;
 }
Exemple #2
0
 /**
  * Test for Inflector::ascii()
  *
  * @test
  */
 public function test_ascii()
 {
     $output = Inflector::ascii('Inglés');
     $expected = "Ingles";
     $this->assertEquals($expected, $output);
 }