001.
<?php
002.
defined(
'BASEPATH'
) OR
exit
(
'No direct script access allowed'
);
003.
004.
class
Add_gallery_event_cl
extends
CI_Controller{
005.
006.
function
__construct()
007.
{
008.
parent::__construct();
009.
010.
$this
->load->model(
'admin/event/add_gallery_event_model'
);
011.
}
012.
013.
014.
015.
function
upload_gallery()
016.
{
017.
018.
$data_file
=
array
();
019.
020.
$id_event
=
$this
->uri->segment(4);
021.
022.
023.
024.
025.
$part_file
=
$_SERVER
[
'DOCUMENT_ROOT'
].
'/file'
;
026.
$year
=
date
(
'Y'
);
027.
$month
=
date
(
'm'
);
028.
$day
=
date
(
'd'
);
029.
030.
031.
if
(
$this
->create_directory_year(
$part_file
,
$year
))
032.
{
033.
034.
035.
036.
if
(
$this
->create_directory_month(
$part_file
,
$year
,
$month
))
037.
{
038.
039.
if
(
$this
->create_directory_day(
$part_file
,
$year
,
$month
,
$day
))
040.
{
041.
042.
$dataInfo
=
array
();
043.
$files
=
$_FILES
;
044.
echo
$cpt
=
count
(
$_FILES
[
'file_upload'
][
'neme'
]);
045.
for
(
$i
=0;
$i
<
$cpt
;
$i
++)
046.
{
047.
048.
sleep(1);
049.
$_FILES
[
'file_upload'
][
'name'
]=
$files
[
'file_upload'
][
'name'
][
$i
];
050.
$_FILES
[
'file_upload'
][
'type'
]=
$files
[
'file_upload'
][
'type'
][
$i
];
051.
$_FILES
[
'file_upload'
][
'tmp_name'
]=
$files
[
'file_upload'
][
'tmp_name'
][
$i
];
052.
$_FILES
[
'file_upload'
][
'error'
]=
$files
[
'file_upload'
][
'error'
][
$i
];
053.
$_FILES
[
'file_upload'
][
'size'
]=
$files
[
'file_upload'
][
'size'
][
$i
];
054.
055.
056.
$config
=
array
(
057.
'upload_path'
=>
$part_file
.
'/'
.
$year
.
'/'
.
$month
.
'/'
.
$day
,
058.
'allowed_types'
=>
'jpg|jpeg|png|gif'
,
059.
'file_name'
=>
date
(
"YmdHis"
)
060.
);
061.
062.
063.
$this
->load->library(
'upload'
,
$config
);
064.
065.
066.
$this
->upload->initialize(
$config
);
067.
068.
069.
if
(!
$this
->upload->do_upload(
'file_upload'
))
070.
{
071.
072.
$ddd
=
count
(
$data_file
);
073.
074.
for
(
$i
=0;
$i
<
$ddd
;
$i
++) {
075.
unlink(
$part_file
.
'/'
.
$data_file
[
$i
]);
076.
}
077.
078.
$data_file
=
''
;
079.
080.
}
else
{
081.
082.
$dataInfo
[] =
$this
->upload->data();
083.
084.
$data_file
[
$i
] =
$year
.
'/'
.
$month
.
'/'
.
$day
.
'/'
.
$dataInfo
[
$i
][
'file_name'
];
085.
086.
}
087.
088.
}
089.
090.
091.
092.
093.
094.
$data_gallery_event
=
array
(
095.
'id_event'
=>
$id_event
,
096.
'file'
=>
$data_file
097.
);
098.
099.
100.
101.
102.
103.
if
(
$this
->add_gallery_event_model->add_gallery_event(
$data_gallery_event
))
104.
{
105.
$status
=
'อัพรูปภาพสำเร็จ'
;
106.
}
else
{
107.
$status
=
'ไม่สามารถอัพรูปภาพได้'
;
108.
}
109.
110.
111.
112.
echo
"<script>
113.
alert(
'$status'
);
114.
window.location.href=
'black_edit_event/$id_event'
;
115.
</script>";
116.
117.
118.
119.
120.
121.
}
else
{
122.
123.
$set_input
[
'error'
] =
array
(
124.
'show_error'
=>
'สร้าง Folder '
.
$day
.
' ไม่สำเร็จ'
,
125.
'url'
=> base_url(
'admin/event/edit_event_cl/'
.
$id_event
)
126.
);
127.
128.
$this
->show_error(
$set_input
);
129.
130.
}
131.
132.
133.
134.
}
else
{
135.
136.
$set_input
[
'error'
] =
array
(
137.
'show_error'
=>
'สร้าง Folder '
.
$month
.
' ไม่สำเร็จ'
,
138.
'url'
=> base_url(
'admin/event/edit_event_cl/'
.
$id_event
)
139.
);
140.
141.
$this
->show_error(
$set_input
);
142.
143.
144.
}
145.
146.
147.
148.
}
else
{
149.
150.
$set_input
[
'error'
] =
array
(
151.
'show_error'
=>
'สร้าง Folder '
.
$year
.
' ไม่สำเร็จ'
,
152.
'url'
=> base_url(
'admin/event/edit_event_cl/'
.
$id_event
)
153.
);
154.
155.
$this
->show_error(
$set_input
);
156.
157.
}
158.
159.
160.
161.
162.
}
163.
164.
165.
166.
function
black_edit_event()
167.
{
168.
$id_event
=
$this
->uri->segment(5);
169.
170.
redirect(
'admin/event/edit_event_cl/'
.
$id_event
);
171.
}
172.
173.
174.
175.
}