- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Codeigniter 将 file_path 插入数据库时遇到问题,我有一个表单字段,用户可以在其中上传任何 jpg|png|gif 文件,上传的文件已成功发送到上传目录并显示成功消息。但是我如何获取上传的特定文件的 file_path 并将其插入数据库。
在我调用模型之前,下面的代码工作正常:
`$this->upload_model->upload_path();`
所以肯定是我的模型有问题,想不通。
这是我的 Controller :
class Upload extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
$this->load->model('upload_model');
}
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);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
// when the code below is uncommented it shows error,otherwise runs
// $this->upload_model->upload_path();
$this->load->view('upload_success', $data);
}
}
}
这是我的模型(显示错误):
class Upload_model extends CI_Model {
// this function will be called instantenneously
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function upload_path(){
// ::::::::UNDER CONSTRUCTION::::::::::
$data = array(
'path' =>$upload_data['full_path'],
);
return $this->db->insert('upload', $data);
}
}
View :
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<?php echo $error;?>
<form method="POST" action="/sandeep/ci/index.php/upload/do_upload" enctype="multipart/form-data" />
<input type="file" name="userfile" size="20" />
<br /><br />
<input type="submit" value="upload" />
</form>
</body>
</html>
最佳答案
用你需要上传到你的数据库中的任何东西创建一个数组...然后将它插入到数据库中把这样的东西放在其他的下面
//create array to load to database
$image_data = $this->upload->data();
$insert_data = array(
'name' => $image_data['file_name'],
'path' => $image_data['full_path'],
'thumb_path'=> $image_data['file_path'] . 'thumbs/'. $image_data['file_name'],
'tag' => $tag
);
$this->db->insert('photos', $insert_data);//load array to database
关于php - 如何使用 codeigniter 将 file_path 插入数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29261128/
我正在编写一个将在 Windows 7 上运行的软件。我正在列出已安装的服务、获取服务的图像路径位置并检查服务文件是否存在。(Dll 或 Exe)。 我正在使用 File.Exist(File_Pat
这个问题在这里已经有了答案: What is the purpose of a context manager in python [duplicate] (1 个回答) 关闭去年。 我正在学习Py
我的目的是拍照并保存。但是如果我在 file_paths.xml 上使用字符串生成器来动态定义文件路径,应用程序会抛出错误。 我有 2 种构建类型(测试、发布)。我想从 files_paths.xml
我正在尝试在一列中上传两个图像文件路径。在我的模型中,我从 $filepath 成功获取第一个图像路径,但 $a 不起作用,我也很困惑 $a 是否正在获取我的第二个图像路径 请帮助我 提前致谢。 我的
我正在使用FastAPI接收图像,对其进行处理,然后将图像作为FileResponse返回。 但是返回的文件是一个临时文件,在端点返回文件后需要将其删除。 @app.post("/send") asy
我在使用 Codeigniter 将 file_path 插入数据库时遇到问题,我有一个表单字段,用户可以在其中上传任何 jpg|png|gif 文件,上传的文件已成功发送到上传目录并显示成功消息
我已经使用以下 res/xml/file_paths.xml 设置了一个 FileProvider: 问题是,我有很多更改 applicationId 的产品风格。有什么方法可以用正确的
尝试打开文件时,我不断收到此No such file or directory 错误。我在做: file = open("http://farm7.static.flickr.com/6064/609
funded=r'C:\Users\hill\Desktop\wheels\Leads(1).csv' funded= read_csv(funded) funded=DataFrame(funded
tl;博士:当我在运行时动态检索 file_path 时,为什么需要 file_paths 资源? 我目前正在通过构建自己的应用程序来学习 Android Studio。 我现在想做的是拍张照片,然后
在不覆盖 file_path 函数的情况下,蜘蛛会下载具有默认“请求 URL 哈希”文件名的所有图像。但是,当我尝试覆盖该函数时,它不起作用。默认输出属性 images 中没有任何内容。 我已经尝试了
如何将 outfile 文件路径传递给 MySQL?我已经尝试过以下方法。它不起作用。 我的 SQL 文件 SET @query = CONCAT('SELECT * FROM `regis
通过使用以下命令在 R 中安装包: install.packages('FILE_PATH', repos=NULL, type = "source") 我收到以下错误: Installing pac
我是一名优秀的程序员,十分优秀!