[eluser]M4rc0[/eluser]
Ok so here i am
Less talk more code this time, since i have lots to show.
I choose Imagination to upload (temp place) and rename and upload (correct place). I'm not using CI upload helper since that would be one extra unnecessary upload. So i had to add a function to rename the picture (random hash) and to display a validation error in case of invalid file type.
I'm not caring about max width or max height since imagination takes care of resizing it according to it's ratio (rocks). Size validation can be important but that can wait
So i only care about file type now, since i was successfully adding with .zip files (or any other extension).
Here's my controller code:
Code:
function add()
{
if($this->validation->run() == FALSE OR $this->resize_img($_FILES['cover']['name'], $_FILES['cover']['tmp_name'],'public/images/covers/') == FALSE)
{
$this->template->write_view('content','movie/add');
$this->template->render();
}
else
{
$this->success();
}
}
function resize_img($name,$path,$dest=FALSE)
{
$this->load->library('imagination');
if($image->valid == TRUE){
$image->resize(400,400);
return $image->new_name; //to add on the db
}else{ return FALSE; } //means invalid file type
}
Now the imagination changes:
I have on the top of the variables a "public $new_name;"
Added the function encrypt_name:
Code:
public function encrypt_name()
{
mt_srand();
$this->new_name = md5(uniqid(mt_rand())).'.'.$this->type;
return $this->new_name;
}
And on your resize function, there's an if in the beginning, i just added the else code:
Code:
if($this->valid)
{ //(...)
}else{$CI->validation->error_string = "Invalid file type.";}
So it works! Not perfectly but it works.
If i choose a file other then a valid image type, it shows the form again but without the "Invalid file type" error.
But at least it doesn't go
My trouble is with $CI variable that i see you get with "$CI =& get_instance();"
I have never worked with that before, so i tought it would set on my controller (CI instance?) the validation error but it's not setting it. Maybe i have to use the return of the resize function for this. What you think?