Php CodeIgniter 4:上载文件
我在使用CodeIgniter 4上传表单中的文件时遇到问题,我找不到问题所在。你能帮帮我吗?文件名正常,问题是它没有将文件移动到指定的目录中,因为我遇到了以下错误:调用成员函数move()时为null。 WRITEPATH的值为:C:\xampp\htdocs\myproject\writable\ 我上传的视图部分如下所示:Php CodeIgniter 4:上载文件,php,codeigniter,Php,Codeigniter,我在使用CodeIgniter 4上传表单中的文件时遇到问题,我找不到问题所在。你能帮帮我吗?文件名正常,问题是它没有将文件移动到指定的目录中,因为我遇到了以下错误:调用成员函数move()时为null。 WRITEPATH的值为:C:\xampp\htdocs\myproject\writable\ 我上传的视图部分如下所示: <div class="card-body"> <label for="exampleInputFile&quo
<div class="card-body">
<label for="exampleInputFile">Fisier</label>
<div class="form-group">
<div class="input-group">
<div class="custom-file">
<input type="file" class="custom-file-input" name="customFile" id="customFile" required>
<label class="custom-file-label" for="exampleInputFile">Alege Fisierul</label>
</div>
</div>
</div>
</div>
$img = $this->request->getFile('customFile');
$img->move(WRITEPATH . 'uploads');
我使用以下内容获取文件名:$this->request->getVar('customFile')
谢谢大家! 在控制器中像这样
$config['upload_path'] = './upload/painting/';
$config['allowed_types'] = 'jpg|png|jpeg'; // here you want to define file type
$config['max_width'] = '250';
$config['max_height'] = '300';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
// $this->upload->do_upload('profile_pic');
if ($this->upload->do_upload('ptn_url')) {
$data = array('upload_data' => $this->upload->data());
// print_r($data);
$_POST['ptn_url'] = "upload/painting/" . $data['upload_data']['file_name'];
$_POST['user_id'] = $this->session->user_data['user_id'];
$route['upload-image'] = 'user';
$route['store-image'] = 'user/add';
$route['painting/(:num)'] = 'painting';
在位于config文件夹的routes.php文件中
您需要为存储映像定义路径
像这样
$config['upload_path'] = './upload/painting/';
$config['allowed_types'] = 'jpg|png|jpeg'; // here you want to define file type
$config['max_width'] = '250';
$config['max_height'] = '300';
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
// $this->upload->do_upload('profile_pic');
if ($this->upload->do_upload('ptn_url')) {
$data = array('upload_data' => $this->upload->data());
// print_r($data);
$_POST['ptn_url'] = "upload/painting/" . $data['upload_data']['file_name'];
$_POST['user_id'] = $this->session->user_data['user_id'];
$route['upload-image'] = 'user';
$route['store-image'] = 'user/add';
$route['painting/(:num)'] = 'painting';
有关文件上载的更多参考信息
我希望这对你有帮助
谢谢…这在Codeigniter 4中起到了作用:
$file = $this->request->getFile('file');
if (!$file->isValid()) {
return $this->fail($file->getErrorString());
}
$file->move(ROOTPATH . 'public\uploads\documents');
$name = $file->getName();
谢谢大家! 这回答了你的问题吗?请出示你的全部表格好吗?您还可以发布$\u文件的输出吗?也许你忘了把你的表格作为多部分。