Php Codeigniter上载文件名
通常我们可以通过使用Php Codeigniter上载文件名,php,codeigniter,Php,Codeigniter,通常我们可以通过使用$this->input->get('field\u name')或$this->input->post('field\u name')在Codeigniter中获取表单数据,这很好 在原始PHP中,我们使用$\u文件[“fileToUpload”][“name”]获取用户试图上载的文件名 我的问题是:是否有Codeigniter方法获取需要上传的文件名 我想说的是,在试图使用Codeigniter库而不是使用原始PHPglobal$\u文件变量将文件保存到我的服务器之前,我
$this->input->get('field\u name')
或$this->input->post('field\u name')
在Codeigniter
中获取表单数据,这很好
在原始PHP
中,我们使用$\u文件[“fileToUpload”][“name”]
获取用户试图上载的文件名
我的问题是:是否有Codeigniter
方法获取需要上传的文件名
我想说的是,在试图使用Codeigniter
库而不是使用原始PHP
global$\u文件
变量将文件保存到我的服务器之前,我需要获取用户试图上传的文件名
<?php
class Upload extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
public function index()
{
$this->load->view('upload_form', array('error' => ' ' ));
}
public function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
// get the user submitted file name here
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
}
?>
这是两个版本的文件是为和
如果要在后端获取文件名:
$this->upload->file\u name
它将基于system/library/upload.php
这个功能
public function data()
{
return array (
'file_name' => $this->file_name,
'file_type' => $this->file_type,
...
);
}
如果需要获取文件名
在保存到服务器之前。。。你有javascript的工作
在调用$this->upload->data()之前,我可以调用$this->upload->do\u upload('userfile')
吗?我编辑了我的答案@MahbubulIslam。。。您是否希望在提交按钮之前获取文件名?或者在提交表单后,我试图说,在尝试将其上载到我的服务器之前,我需要知道用户试图上载的文件名。我已编辑了我的答案,以使其更清楚。请检查。我需要后端的名称。
public function data()
{
return array (
'file_name' => $this->file_name,
'file_type' => $this->file_type,
...
);
}
<script>
function changeEventHandler(event){
alert(event.target.value);
}
</script>