|
 |
|
เช็คค่าว่างของ file ที่อัพโหลดครับ ผมอยากรู้ว่าถ้าจะเช็คค่า วางของ type ="file" ต้องเขียน if else อย่างไร |
|
 |
|
|
 |
 |
|
ผมอยากเช็คว่า ถ้าไม่ทำการเพิ่มรูปจะ ไม่ต้องเซฟรูป แต่ ถ้าทำการเพิ่มรูปให้เซฟรูปครับ

Code (PHP)
$id = $this->input->post("id");
$title = $this->input->post("title");
$description = $this->input->post("description");
$url = $this->input->post("url");
$file_name = $this->input->post("file_name");
$this->load->library('upload');
$config['upload_path'] = './uploads/member';
$config['allowed_types'] = 'gif|jpg|png|jpeg|mp4';
$config['max_size'] = '102400';
$config['max_width'] = '10000';
$config['max_height'] = '10000';
$name_file = "uploads-".time();
$config['file_name'] = $name_file;
// print_r($config['upload_path']);
// Alternately you can set preferences by calling the ``initialize()`` method. Useful if you auto-load the class:
$this->upload->initialize($config);
$editdata = array();
if(empty($file_name))
{
$editdata = array(
'title' => $title,
'description' => $description,
// 'file_name' => $gamber['file_name'],
'url' => $url,
'update_at' => date("Y-m-d H:i:s")
);
}
else
{
if ($_FILES['file_name']['name']) {
$field_name = 'file_name';
if ($this->upload->do_upload('file_name')){
$gamber = $this->upload->data();
$editdata = array(
'title' => $title,
'description' => $description,
'file_name' => $gamber['file_name'],
'url' => $url,
'update_at' => date("Y-m-d H:i:s")
);
}
}
}
$this->db->where('id', $id);
$resultsedit = $this->db->update('tbl_member',$editdata);
if($resultsedit > 0)
{
$this->session->set_flashdata('success', 'successly');
}
else
{
$this->session->set_flashdata('error', 'failed');
}
redirect('member');
#ปกติเราจะเช็คค่าวาง ของ input type="text" ด้วยการเขียน เงื่อนไขโดยใช้ empty ใช่ไหมครับ
แต่ผมอยากเช็คเป็น input type="file" เราจะเขียนเงื่อนไขแบบไหนครับ
ขอความกรุณาด้วยครับ ขอบคุณครับ
#CodeIgniter นะครับ
Tag : PHP, CodeIgniter

|
|
 |
 |
 |
 |
Date :
2018-10-17 08:19:09 |
By :
1711167185640399 |
View :
994 |
Reply :
3 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
คำค้น
codeigniter file upload validation required
|
 |
 |
 |
 |
Date :
2018-10-17 09:55:07 |
By :
Chaidhanan |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|