Welcome Guest, Not a member yet? Register   Sign In
how check a field whose field's type is a file using CI rule?
#1

[eluser]chmod[/eluser]
i have another question:


like this:
controller:
-------------------
function _check_tgmember_exist($username){
$this->load->model('center/personal/becometgmember_model');
$result_check = $this->becometgmember_model->_check_tgmember_exist($username);
if ($result_check){
return TRUE;
}else{
$this->validation->set_message('_check_tgmember_exist','failed');
return FALSE;
}
}

$username = $this->input->post('username');
$rules['username'] = "trim|required|xss_clean|callback__check_tgmember_exist";

but when the input is a multipart,
by this way,when the field's type is file,how can i check user to upload his picture with ruels?

like these:

view:
------------
<?=form_open_multipart('iBecometgmember');?>
<div>
<label for="cardid_pic">news:</label>
&lt;input type="file" name="cardid_pic" id="cardid_pic" /&gt;
</div>
...
<div>
&lt;input type="submit" name="Submit" value="submit" /&gt;
</div>
&lt;/form&gt;


controller:
----------------


$cardid_pic = $this->input->post('cardid_pic');
$rules['cardid_pic'] = "trim|required|callback__check_cardid_pic";

function _check_cardid_pic($cardid_pic){
if ($cardid_pic){
return TRUE;
}else{
return FALSE;
}
}

but the $cardid_pic = null,

how can I do???
#2

[eluser]ngkong[/eluser]
for file type, the variable is: $_FILES['field_name']
the filename will be: $_FILES['field_name']['name']

if you want to check the uploaded file extension, you can call: pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)
#3

[eluser]chmod[/eluser]
[quote author="ngkong" date="1210102573"]for file type, the variable is: $_FILES['field_name']
the filename will be: $_FILES['field_name']['name']

if you want to check the uploaded file extension, you can call: pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION)[/quote]


perfect,thanks.




Theme © iAndrew 2016 - Forum software by © MyBB