计算上传的文件数

编程入门 行业动态 更新时间:2024-10-28 09:26:22
本文介绍了计算上传的文件数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

但是,我需要一些方法来计算上传文件的数量,因为我想限制在某些情况下(但不是全部)。

我该怎么做?我尝试了 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'); }

任何帮助是非常感激。

$ _ FILES 变量中的项目数:

$ 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.

更多推荐

计算上传的文件数

本文发布于:2023-10-16 06:59:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496806.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:上传   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!