The CI official website manual says, file upload:
function getuploadname ($field = "Prize_file")
{
$config [' upload_path '] = ' uploads/prizepath/';
$config [' allowed_types '] = ' gif|jpg|png|swf|bmp|txt ';
$config [' file_name '] = date (' Ymdhis '). Rand (100, 999);
$config [' max_size '] = ' 1024 ';
$config [' max_width '] = ' 0 ';
$config [' max_height '] = ' 0 ';
$this->load->library (' upload ', $config);
if (!dir_create ($config [' Upload_path ']))
{
exit (' Error uploading directory ');
if (! $this->upload->do_upload ($field))
{
$data = array (' ERROR ' = $this->uploa D->display_errors ());
}
Else
{
$data = array (' upload_data ' = = $this->upload->data ());
return $data;
}
This is a single file upload with the file format:
Array (size=5) =
String
' 640-300-50k.jpg ' (length=15) =
String
' Image/jpeg ' (length=10) =
String
' E:\wamp\tmp\php9A91.tmp ' (length=23) =
Int
0 =
Int
50953
If you want to upload multiple files:
The format of the file is:
Array (size=5) = Array (size=4) =
String
' 640-300-50k.jpg ' (length=15) =
String
' 20160727051524365.jpg ' (length=21) =
String
"' (length=0) =
String
"' (length=0) = Array (size=4) =
String
' Image/jpeg ' (length=10) =
String
' Image/jpeg ' (length=10) =
String
"' (length=0) =
String
"' (length=0) = Array (size=4) =
String
' E:\wamp\tmp\php79C9.tmp ' (length=23) =
String
' E:\wamp\tmp\php79CA.tmp ' (length=23) =
String
"' (length=0) =
String
"' (length=0) = Array (size=4) =
Int
0 =
Int
0 =
Int
4 =
Int
4 = Array (size=4) =
Int
50953 =
Int
42920 =
Int
0 =
Int
0
The key idea at this time is:
Upload multiple files, assemble into a single file upload format, and, each file name to be different, attach code:
foreach ($_files[' prize_file ' [' Error '] as $k = $v) {
if ($v!=4) {
$field = "Prize_file". $k; ----------(This step is critical)
$_files[$field]=array ("name" =>$_files["Prize_file" [' Name '] [$k], "type" =>$_files[' prize_file ' [' type '] [$k ], "Tmp_name" =>$_files[' prize_file ' [' tmp_name '] [$k], "error" =>$_files[' prize_file ' [' Error '] [$k], "size" = >$_files[' prize_file ' [' Size '] [$k]);
$data = $this->getuploadname ($field); -------(this time, the name of each file upload is different)
$upload _data[]= $data;
}
}
CI Multi-File upload