我无法获得使用codeignter3 fileupload()返回的上传文件



我在codeigniter3对应的模型文件中有如下的文件上传代码:

$config['upload_path']      = './assets/img/report/';
$config['allowed_types']    = 'txt|odt|jpg|png|jpeg|pdf|docx';
$config['file_name']        = $this->id;
$config['overwrite']        = true;
$config['max_size']         = '150000';

$this->load->library('upload', $config);
if ($this->upload->do_upload('file')) {
return $this->upload->data('file_name');
}
return default.jpg;

对应的视图文件有以下代码

<div class="form-group">
<label for="file">Attachment</label>
<input class="form-control-file"
type="file" name="file" />
<div class="invalid-feedback">
<?php echo form_error('file') ?>
</div>
</div>

但是代码总是返回default.jpg。我如何修复正确返回上传的文件。我使用CI3在Debian 11运行xampp8.1

**Configure your upload path**
After upload this will send you upload data or the upload error
$config = array(
'upload_path' => "./assets/img/report/",
'allowed_types' => "gif|jpg|png|jpeg|pdf",
'overwrite' => TRUE,
'max_size' => "2048000",
'max_height' => "768",
'max_width' => "1024"
);
$this->load->library('upload', $config);
if($this->upload->do_upload())
{
$data = array('upload_data' => $this->upload->data());
return $data;
}
else
{
$error = array('error' => $this->upload->display_errors());
}
}

相关内容

  • 没有找到相关文章

最新更新