【发布时间】:2014-02-24 05:51:46
【问题描述】:
我正在尝试上传文件并将其名称替换为标题名称,但我无法通过控制器中的 echo 获取文件名,即使不是作为分析器中的 POST。
我还需要重命名它,但在此之前我需要知道发布值,即文件名。
我在这里发布我的代码。
我的看法
<?php echo form_open_multipart('emailtemplate/do_upload');?>
<tr class='odd gradeX'>
<td class='center'>
<input type="file" name="userfile" size="20" />
</td>
<td class='center'>
<input placeholder='Title For Your File' name='title' class='form-control'>
<td class='center'>
<input placeholder='Comment On File' name='comment' class='form-control'>
</td>
</tr>
<input type="submit" value="upload" />
</form>
我的控制器
function do_upload()
{
$this->load->helper('form');
$this->load->helper('html');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '1000';
$config['encrypt_name'] = true;
//$file=$this->input->post('userfile');
$this->load->library('upload', $config);
$this->upload->data();
$file_name = $this->upload->do_upload('userfile');
echo $file_name;
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('add/addfile', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('add/addfile', $data);
}
$this->output->enable_profiler(true);
}
【问题讨论】:
-
在 codeIgniter 中通过
$this->input->post();访问 post 值,与 $_POST 相同 -
上传的文件如何重命名??
标签: php codeigniter file-upload