Welcome Guest, Not a member yet? Register   Sign In
Validation and file upload
#1

[eluser]dimis[/eluser]
I have done a validation rule for a form with CI validation.
Is there a way to put a file input as require?
Dimis
#2

[eluser]Bramme[/eluser]
Not that I know off, but you can check with $_FILES['userfile']['error'] == 4 if there was a file selected or not.

Mind you, you won't be able to repopulate it, as that's against safety regulations.
#3

[eluser]dimis[/eluser]
Is there a way to resize a image at uploading time?
#4

[eluser]Unknown[/eluser]
dimis: Yes, it is possible. Here is an example:

Code:
//STORE USER UPLOADED IMAGE
$config_upload['upload_path'] = '/path/to/images/directory/';
$config_upload['allowed_types'] = 'jpg';
$config_upload['max_size']    = '1000';
$config_upload['encrypt_name'] = TRUE;

$this->load->library('upload', $config_upload);
$this->upload->do_upload('imagen');

//RESIZE IMAGE TO A MAXIMUM OF 450px WIDTH OR HEIGHT
$datos_imagen = $this->upload->data();

$config_resize['image_library'] = 'gd2';
$config_resize['source_image'] = $datos_imagen['full_path'];
$config_resize['maintain_ratio'] = TRUE;
$config_resize['width'] = 450;
$config_resize['height'] = 450;

$this->load->library('image_lib', $config_resize);

$this->image_lib->resize();

It's just an example, there are other possibilities. I suggest you check the File Upload and Image Manipulation classes.
#5

[eluser]phantom-a[/eluser]
I think resizing is must for uploaded images. Sometimes they can put php code hack into the image, resizing would effectively null any code cleverly embedded in a image
http://ha.ckers.org/blog/20070604/passin...imagesize/
#6

[eluser]ontguy[/eluser]
There is a way to validate using CI Validation:
http://ellislab.com/forums/viewthread/87756/#442385
#7

[eluser]dimis[/eluser]
Thang you.
I thing I will extend the validation class but not for this, as megabyte wrote the upload function check if file exists
#8

[eluser]ontguy[/eluser]
np. Keep this reply in mind while validating the file upload.
http://ellislab.com/forums/viewthread/87756/#442182

You could avoid that when you extend the validation class.
#9

[eluser]dimis[/eluser]
Thank you.
I will use it!




Theme © iAndrew 2016 - Forum software by © MyBB