0

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.

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.

Unfortunately, have checked with the company with have hosting with, the most I can get out of our ftp is 755.

Question 1)

Is there another alternative in Codeigniter to do file uploads that will only require 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

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.

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

Question 2)

Does anyone know of any tutorials that are Codeigniter specific for uploading files to a database? It seems to me that this is the only other alternative to using a file system.

Community
  • 1
  • 1
Zigu
  • 1,625
  • 4
  • 23
  • 33
  • MMMmmm. Tried the tutorial on the codeigniter. It seems 755 is enough permissions to upload using a filesystem based solution. I would still like to know if there is a Database type solution. Also, why is 777 the recommended permission setting as well? – Zigu Nov 10 '11 at 03:26

1 Answers1

5

Sounds like you need to change your host if can't cmod to anything else besides 755.

Other than that, uploading files in CodeIgniter doesn't need to be done with the File Upload class. 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.

zkanoca
  • 9,664
  • 9
  • 50
  • 94
Repox
  • 15,015
  • 8
  • 54
  • 79