计算上传的文件数 [英] Counting the number of uploaded files
问题描述
但是,我需要一些方法来计算上传文件的数量,因为我想限制在某些情况下(但不是全部)。
我该怎么做?我尝试了 count($ _ FILES)
但是这给我没什么用。
,但都没有提供我需要的信息。
上传表单是一个多文件上传,我使用此媒体库可处理多次上传。
无计数功能的上传功能像这样:
function do_upload()
{
$ setid = $ this-& > post('imageset');
$ this-> load-> library('upload');
$ this-> load-> library('image_lib');
$ this-> upload-> initialize(array(
upload_path=>./photos/,
allowed_types=>jpg | jpeg | png | gif,
encrypt_name=> TRUE
));
try {
$ this-> upload-> do_multi_upload(files);
$ images = $ this-> upload-> get_multi_upload_data();
$ config = array(
'image_library'=>'gd2',
'create_thumb'=> TRUE,
'maintain_ratio'=> TRUE,
'width'=>'145',
'height'=>'145'
);
foreach($ images as $ image)
{
$ config ['source_image'] = $ image ['full_path'];
$ this-> image_lib-> initialize($ config);
$ this-> image_lib-> resize();
$ this-> manage_model-> insertimage($ image ['file_name'],$ image ['orig_name'],$ image ['file_size'],$ image ['file_type'],$ setid) ;
}
$ this-> session-> set_flashdata('success','Billederne er nu blevet uploadet。');
} catch(Exception $ e){
$ this-> session-> set_flashdata('error',$ e);
}
redirect('manage / images','refresh');
}
任何帮助是非常感激。
$ total = count($ _ FILES ['your_variable_array_in_html'] ['tmp_name']);
您需要在:
$ this-> upload-> do_multi_upload(files);
行。
注意, $ _ FILES
只包含一个变量 - 一个数组,包含不同部分的数组, tmp_name
, name
,错误
等。请检查手动了解详情。
I am working on my CodeIgniter project, and it is so far working very well.
However, I need some way to count the number of uploaded files, since I want to limit it in some cases (but not all).
How can I do that? I tried count($_FILES)
but that gave me nothing usable.
I also tried a bunch of other things, but neither gave me the information I need.
The upload form is a multiple file upload, and I am using this library to handle multiple uploads.
The upload function without the counting looks like this:
function do_upload()
{
$setid = $this->input->post('imageset');
$this->load->library('upload');
$this->load->library('image_lib');
$this->upload->initialize(array(
"upload_path" => "./photos/",
"allowed_types" => "jpg|jpeg|png|gif",
"encrypt_name" => TRUE
));
try {
$this->upload->do_multi_upload("files");
$images = $this->upload->get_multi_upload_data();
$config = array(
'image_library' => 'gd2',
'create_thumb' => TRUE,
'maintain_ratio' => TRUE,
'width' => '145',
'height' => '145'
);
foreach ($images as $image)
{
$config['source_image'] = $image['full_path'];
$this->image_lib->initialize($config);
$this->image_lib->resize();
$this->manage_model->insertimage($image['file_name'],$image['orig_name'],$image['file_size'],$image['file_type'],$setid);
}
$this->session->set_flashdata('success','Billederne er nu blevet uploadet.');
} catch (Exception $e) {
$this->session->set_flashdata('error', $e);
}
redirect('manage/images','refresh');
}
Any help is very appreciated.
You can check the number of items in your $_FILES
variable using for example:
$total = count($_FILES['your_variable_array_in_html']['tmp_name']);
You need to do that before the:
$this->upload->do_multi_upload("files");
line.
As you have already noticed, $_FILES
only contains one variable - an array - containing arrays of the different sections, tmp_name
, name
, error
, etc. Check the manual for more details.
这篇关于计算上传的文件数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!