|
|
|
อัพโหลดรูปภาพหลายๆรูปไม่ได้ ขึ้น error Warning --> count(): Parameter must be an array or an object that implements Countable |
|
|
|
|
|
|
|
ผลใช้ framawork CI แล้วไม่สามารถอัพรูปภาพหลายๆรูปภาพได้ในเวลาเดียวกัน
ลองในเครื่องที่จำลองสามารถใช้ได้ไม่ขึ้น errorอะไร แต่พออัพขึ้น server จริงแล้วไม่สามารถใช้ได้ครับ error บรรทัดที่ 44 ตรง count($_FILES['file_upload']['name']); ครับ
โค็ดส่วน controllers ส่วนอัพรูปภาพ
Code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Add_gallery_event_cl extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->model('admin/event/add_gallery_event_model');
}//function __construct
function upload_gallery()
{
$data_file = array();
$id_event = $this->uri->segment(4);
//$id_category = $this->uri->segment(5);
$part_file = $_SERVER['DOCUMENT_ROOT'].'/file';
$year = date('Y');
$month = date('m');
$day = date('d');
if ($this->create_directory_year($part_file,$year))
{
if ($this->create_directory_month($part_file,$year,$month))
{
if ($this->create_directory_day($part_file,$year,$month,$day))
{
$dataInfo = array();
$files = $_FILES;
echo $cpt = count($_FILES['file_upload']['neme']);
for ($i=0; $i<$cpt ; $i++)
{
sleep(1);
$_FILES['file_upload']['name']= $files['file_upload']['name'][$i];
$_FILES['file_upload']['type']= $files['file_upload']['type'][$i];
$_FILES['file_upload']['tmp_name']= $files['file_upload']['tmp_name'][$i];
$_FILES['file_upload']['error']= $files['file_upload']['error'][$i];
$_FILES['file_upload']['size']= $files['file_upload']['size'][$i];
$config = array(
'upload_path' => $part_file.'/'.$year.'/'.$month.'/'.$day,
'allowed_types' => 'jpg|jpeg|png|gif',
'file_name' => date("YmdHis")
);
$this->load->library('upload',$config);
$this->upload->initialize($config);
if (! $this->upload->do_upload('file_upload'))
{
$ddd = count($data_file);
for ($i=0; $i<$ddd ; $i++) {
unlink($part_file.'/'.$data_file[$i]);
}
$data_file = '';
} else {
$dataInfo[] = $this->upload->data();
$data_file[$i] = $year.'/'.$month.'/'.$day.'/'.$dataInfo[$i]['file_name'];
}//if else ! $this->upload->do_upload('file_upload')
}//for
$data_gallery_event = array(
'id_event' => $id_event,
'file' => $data_file
);
if ($this->add_gallery_event_model->add_gallery_event($data_gallery_event))
{
$status = 'อัพรูปภาพสำเร็จ';
} else {
$status = 'ไม่สามารถอัพรูปภาพได้';
}//if else check add_gallery_event
echo "<script>
alert('$status');
window.location.href='black_edit_event/$id_event';
</script>";
} else {
$set_input['error'] = array(
'show_error' => 'สร้าง Folder '.$day.' ไม่สำเร็จ',
'url' => base_url('admin/event/edit_event_cl/'.$id_event)
);
$this->show_error($set_input);//show error view
}// if create_directory_day
} else {
$set_input['error'] = array(
'show_error' => 'สร้าง Folder '.$month.' ไม่สำเร็จ',
'url' => base_url('admin/event/edit_event_cl/'.$id_event)
);
$this->show_error($set_input);//show error view
}//if else create_directory_month
} else {
$set_input['error'] = array(
'show_error' => 'สร้าง Folder '.$year.' ไม่สำเร็จ',
'url' => base_url('admin/event/edit_event_cl/'.$id_event)
);
$this->show_error($set_input);//show error view
}//if else check create_directory_year
}//function upload
function black_edit_event()
{
$id_event = $this->uri->segment(5);
redirect('admin/event/edit_event_cl/'.$id_event);
}//function black_edit_event
}//class Add_gallery_event_cl
โค็ดส่วน controllers ส่วนset ข้อมูลที่แสดงผล
Code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Edit_event_cl extends CI_Controller{
function __construct()
{
parent::__construct();
$this->load->model('admin/event/edit_event_model');
}//function __construct
function index()
{
$dataheader = array(
'title' => 'เขตสุขภาพที่13',
);
$id_event = $this->uri->segment(4);
$data_event = $this->edit_event_model->list_edit_event($id_event);
$data_category = $this->edit_event_model->list_category();
$data_category_sp = $this->edit_event_model->list_category_sp();
$set_input['date_edit_event_gallery'] = $this->edit_event_model->list_edit_event_gallery($id_event);//select gallery form event
$set_input['ID_event'] = $data_event['E_id'];
$set_input['ID_category'] = $data_event['C_id'];
$this->load->helper('form');
//$this->load->library('form_validation');
/***************************stert set input add gayyery***************************/
$set_input['file_add_gallery'] = array(
'name' => 'file_upload[]',
'multiple' => 'multiple'
);
$set_input['submit_add_gallery'] = array(
'value' => 'upload',
);
/***************************end set input add gayyery***************************/
if($_SESSION['STATUS_LOGIN'] == 'CONFIRM_LOGIN') {
if ($_SESSION['STATUS'] == 'SUPER_ADMIN' || $_SESSION['STATUS'] == 'ADMIN') {
$data_show['header'] = $this->load->view('admin/header_view',$dataheader,TRUE);
$data_show['nav'] = $this->load->view('admin/nav_view','',TRUE);
$data_show['info'] = $this->load->view('admin/event/edit_event_view',$set_input,TRUE);
$data_show['footer'] = $this->load->view('admin/footer_view','',TRUE);
$this->load->view('admin/show_wed_view',$data_show);
} else {
redirect('admin/login_cl/error_logout');
}
} else {
redirect('admin/login_cl/1');
}
}//function index
function update_event()
{
$data = array(
'id_event' => $this->uri->segment(4),
'category' => $this->input->post('category'),
'category_sp' => $this->input->post('category_sp'),
'title' => $this->input->post('title'),
'data_post' => $this->input->post('data_post'),
'category' => $this->input->post('category'),
);
if ($this->edit_event_model->update_event($data))
{
$status = 'แก้ไขภาพกิจกรรมสำเร็จ';
} else {
$status = 'ไม่สามารถแก้ไขภาพกิจกรรม';
}//if else check update database
echo "<script>
alert('$status');
window.location.href='black_index_event';
</script>";
}//function update_event
function black_index_event()
{
redirect('admin/event/index_event_cl');
}//function black_index_event
}//class edit_event_cl
ส่วน view
Code
<div class="col-lg-6">
<div class="card">
<div class="card-header">
<strong>Add Gallery:<?=$nane_event?></strong>
</div><!--<div class="card-header">-->
<div class="card-body card-block">
<?=form_open_multipart('admin/event/upload_gallery/'.$ID_event);?>
<div class="row form-group">
<div class="col col-md-3"><label for="text-input" class=" form-control-label">ไฟล์</label></div>
<div class="col-12 col-md-9">
<?=form_upload($file_add_gallery);?>
</div><!--<div class="col-12 col-md-9">-->
</div><!--div class row form-group-->
<button type="submit" class="btn btn-primary btn-sm"><i class="fa fa-dot-circle-o"></i>Submit</button>
<button type="reset" class="btn btn-danger btn-sm"><i class="fa fa-ban"></i>Reset</button>
<a href="<?=base_url('admin/event/index_event_cl')?>" class="btn btn-warning btn-sm"><i class="fa fa-chevron-left">Cancel</i></a>
</div><!--<div class="card-body card-block">-->
</div><!--<div class="card">-->
</div><!---<div class="col-lg-6">-->
Tag : PHP, CodeIgniter
|
ประวัติการแก้ไข 2018-11-09 16:50:04 2018-11-09 16:50:59 2018-11-09 16:55:07 2018-11-09 16:55:48 2018-11-09 19:19:09 2018-11-09 19:20:13
|
|
|
|
|
Date :
2018-11-09 16:49:07 |
By :
pop41554 |
View :
1030 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เลือก tag php ครอบ โค๊ดหน่อยครับ
|
|
|
|
|
Date :
2018-11-09 17:03:43 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ตอนนี้ได้แล้วครับพอรู้สาเหตุแล้วครับ เกิดจาก php.ini มันอัพโหลดรูปภาพได้แค่ 2M ต้องไปขยายค่า upload_max_filesize กับ post_max_size หายเลยครับ
|
|
|
|
|
Date :
2018-11-09 20:22:49 |
By :
pop41554 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|