Skip to content

Instantly share code, notes, and snippets.

@fabiancarlos
Created May 27, 2012 19:37
Show Gist options
  • Save fabiancarlos/2815622 to your computer and use it in GitHub Desktop.
Save fabiancarlos/2815622 to your computer and use it in GitHub Desktop.
upload the image ~ Kohana 3.2 com plugin multi.js
<?php
// validation file image
$files = Validation::factory($_FILES)
->rule('imagem', 'Upload::type', array(':value', array('jpg', 'png', 'gif')));
// if file image is not empty, just do it bob!!! =:^D
if ($files->check() && !empty($_FILES['imagem']['name'][0])){
// pega o ultimo ID do servicos
$servico_last_id = $servico->get_last_id_servico();
$time_now = $time_now->format('Y_m_d_H_i_s');
# troca espaços por underline
Upload::$remove_spaces = TRUE;
foreach ($_FILES['imagem']["error"] as $key => $value){
$image['name'] = preg_replace('/\s+/', '', $_FILES['imagem']['name'][$key]);
$image['type'] = $_FILES['imagem']['type'][$key];
$image['tmp_name'] = $_FILES['imagem']['tmp_name'][$key];
$image['error'] = $_FILES['imagem']['error'][$key];
$image['size'] = $_FILES['imagem']['size'][$key];
// Upload the file
Upload::save($image, $image['name'], $this->_path);
// get the path of the image uploaded
$img_path = $this->_path . $image['name'];
// create the new name with the time indexed
$img_new = $time_now . $image['name'];
var_dump($_FILES);
// Upload, Resize and re-name the image
// re-upload the new image
Image::factory($img_path)
->resize(230, NULL)
->save($this->_path . $img_new);
// delete the image uploaded first
unlink($img_path);
$values_img['id'] = '';
$values_img['id_servico'] = $servico_last_id;
$values_img['img'] = (string) $img_new;
$servico->insert_servico_img($values_img);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment