简体   繁体   English

Codeigniter:文件上传

[英]Codeigniter: File uploading

The app I am developing requires taking in a PDF from a user and modifying it then spitting it back out for other users to use. 我正在开发的应用程序需要从用户处获取PDF并进行修改,然后将其吐出来以供其他用户使用。

Having looked into the Table of contents guide, I found that the File Upload directory that you mention in the config file path has to have ftp chmod 777 enabled. 查看目录指南后,我发现您在配置文件路径中提到的F​​ile Upload目录必须启用ftp chmod 777。

Unfortunately, have checked with the company with have hosting with, the most I can get out of our ftp is 755. 不幸的是,与托管公司一起检查过,我能从我们的ftp中获得的最多的是755。

Question 1) 问题1)

Is there another alternative in Codeigniter to do file uploads that will only require chmod 755? Codeigniter中还有另一种方法可以只需要chmod 755来上传文件吗?

Also, I looked into uploading to the database instead. 另外,我还考虑了上传到数据库。 The closest relevant question I could find was as follows: 我能找到的最接近的相关问题如下:

codeigniter image uploading mysql Codeigniter图片上传mysql

While I have found articles that detail how to upload any file to a database for php in general (such as below), none of the ones I have found have been particular to CodeIgniter integration. 虽然我找到了一些文章,这些文章详细介绍了一般如何将任何文件上传到php数据库(例如下面),但是我发现的文件都不是CodeIgniter集成所特有的。

Article: http://www.phpriot.com/articles/storing-images-in-mysql 文章: http : //www.phpriot.com/articles/storing-images-in-mysql

Question 2) 问题2)

Does anyone know of any tutorials that are Codeigniter specific for uploading files to a database? 有人知道Codeigniter专门用于将文件上传到数据库的任何教程吗? It seems to me that this is the only other alternative to using a file system. 在我看来,这是使用文件系统的唯一其他选择。

Sounds like you need to change your host if can't cmod to anything else besides 755. 听起来,如果不能将cmod更改为除755以外的任何其他设备,则需要更改主机。

Other than that, uploading files in CodeIgniter doesn't need to be done with the File Upload class. 除此之外,不需要使用File Upload类在CodeIgniter中上传文件。 You are free to use your own method. 您可以自由使用自己的方法。

The controller method 控制器方式

public function save_file()
{

    $file_data = file_get_contents($_FILES['user_file']['tmp_name']);
    $file_name = $_FILES['user_file']['name'];

    $this->database_file_model->insert($file_data, $file_name);
    redirect('file/uploaded');

}

The database file model method 数据库文件模型方法

public function insert($data, $name)
{
  $data['filedata'] = $data;
  $data['filename'] = $name;
  $this->db->insert('mytable', $data);

    // Produces: INSERT INTO mytable (filedata, filename) VALUES (blob, 'Filename')
}

There is no validation in these examples, but should give you the basic idea. 这些示例中没有验证,但是应该给您基本概念。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM