如果在input:file
中选择(Choice
或Browse...
(文件,如何知道用php运行一些代码?
<form action="#" method="post" enctype="multipart/form-data">
<input type="file" name="userfile[]" valign="baseline">
</form>
if(select file){
run my code
}
更新:
我使用JQuery和Code Igniter的Multiple Uploads,当我不选择文件时,输出print_r($_FILES['userfile']);
是:
数组([error]=>4[name]=>[size]=>0[tmp_name]=>[type]=>[key]=>用户文件(
[error] => 4
是->您没有选择要上载的文件。
如果我选择文件,如果我在input:file
中有以下错误:name="userfile[]"
:
此处的Message: Undefined index: userfile
:print_r($_FILES['userfile']);
更新2:我使用来自这些控制器,但如果不选择文件,在这里if ( ! $files )
返回为false并给出错误。我想如果用户没有选择文件没有得到错误如果
class Upload extends Controller {
function Upload()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form');
}
function do_upload()
{
if($_FILE('userfile')){
$config['upload_path'] = './uploads/'; // server directory
$config['allowed_types'] = 'gif|jpg|png'; // by extension, will check for whether it is an image
$config['max_size'] = '1000'; // in kb
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->load->library('Multi_upload');
$files = $this->multi_upload->go_upload();
if ( ! $files )
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
} else {
$data = array('upload_data' => $files);
$this->load->view('upload_success', $data);
}
}
redirect('inse/show');
}
}
<?php
if (isset($_FILES['my_file_input'])) {
// your code
}
?>
注意:如果我说对了,你描述了一个错误的输入类型-文件输入应该使用这个签名:
<input type="file" name="my_file_input" />
注意:文件输入所在的表单应该将其enctype设置为"多部分表单数据"(或类似的内容(。
UPD:我可能错了,但这是您指定的模块的控制器:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Upload extends Controller {
function Upload()
{
parent::Controller();
$this->load->helper(array('form', 'url'));
}
function index()
{
$this->load->view('upload_form');
}
function do_upload()
{
$config['upload_path'] = './uploads/'; // server directory
$config['allowed_types'] = 'gif|jpg|png'; // by extension, will check for whether it is an image
$config['max_size'] = '1000'; // in kb
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->load->library('Multi_upload');
$files = $this->multi_upload->go_upload();
if ( ! $files )
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
} else {
$data = array('upload_data' => $files);
$this->load->view('upload_success', $data);
}
}
}
?>
如果仍然没有得到任何令人满意的结果,请尝试var_dump($_FILES);
并了解文件的存储方式。