codeigniter - 获取使用 dropzone 上传的文件的文件路径
问题描述
如何获取在 CodeIgniter 中使用 dropzone 上传的文件的文件路径?
我的视图页面是
<form action="<?php echo site_url('Upload/imageUploadPost');?>" class="dropzone" id="my-awesome-dropzone" enctype="multipart/form-data" method="post">
<div class="fallback">
<input name="userfile" type="file"/>
</div>
</form>
我的控制器是
public function imageUploadPost()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1024;
$this->load->library('upload', $config);
$this->upload->do_upload('file');
//here I need to fetch the uploaded file details like name ,path
}
解决方案
希望对你有帮助 :
上传成功后使用$this->upload->data();
获取文件详细信息,你的方法应该是这样的::
public function imageUploadPost()
{
//print_r($_FILES);die;
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1024;
$this->load->library('upload', $config);
if ($this->upload->do_upload('userfile'))
{
$data = array('upload_data' => $this->upload->data());
/* for full file path use $data['full_path'] and so like this */
$file_path = $data['full_path'];
echo $file_path ;
var_dump($data);
die();
}
else
{
$error = array('error' => $this->upload->display_errors());
var_dump($error);
die();
}
}
更多信息:https ://www.codeigniter.com/user_guide/libraries/file_uploading.html
推荐阅读
- node.js - 将 Socket IO 与节点 js socket.to(socket.id).emit() 一起使用会引发错误
- wso2 - wso2-apim 发布者在加载 api 时卡住
- excel - 日期在图表上显示为 1900 年
- javascript - 将 css 变量作为画布过滤器传递
- neo4j - 创建节点并为其设置 ID 而不复制字段
- macos - 对来自 macos 终端的所有连接使用 nexus 默认令牌/凭据
- android - 无法在 android studio 中运行模拟器
- android - 为什么我会收到此错误“从服务器收到状态代码 401:未经授权”?
- c - C/C++:当服务器重新启动时,客户端永远不会恢复 DTLS 连接
- ios - SwiftUI,如何禁用对列表项的触摸,但对列表项的子视图启用触摸?