CodeIgniter - Uploading an Image through a form, store the location of the image in database

By : scrot

I'm trying to upload an image to my site through a form, however it's much more efficient to (rather than bog down the database) just store the location of the image in the database.

I'm having trouble with my form and really don't know where to go:

 //other form data
 Image: <input type="file" name="image" size="20" /> <br>
 <input type="submit" value="Submit" />

Now the form itself works fine, the problem is that it's trying to store the image into the database field 'image' (which is type TEXT). What's the easiest way to tell it to just store the file, and give the file location to store in the 'image' field? (I tell it where to upload the file via the controller).


Edit: controller code (for this part):

function submit_new(){
	$config['upload_path'] = './images/';
	$config['allowed_types'] = 'gif|jpg|png';
	$config['max_size']	= '2000';
	$config['max_width']  = '1024';
	$config['max_height']  = '768';		
	$this->load->library('upload', $config);

	$this->db->insert('post', $_POST);

By : scrot


use the model pages to upload data to database

By : abcdef

I've done pretty extensive development in Ruby and Groovy (as well as a little Jython using Grinder as a load testing tool).

Of the 3, I prefer Groovy the most. I like the closure syntax the best and I think that it has the tightest integration in how it works with other java classes on the JVM. It's been a little while since I last used JRuby, but importing Java classes and working with the classloader in JRuby didn't feel as clean to me.

The fact that Groovy is also essentially a superset of Java means that the huge population of Java programmers out there will have a quicker uptake time in picking Groovy up over Ruby/JRuby. They can start programming it like it's Java and slowly start inserting idomatic groovy as they pick it up.

More to the point of what you're asking, I think that another advantage of Groovy is that the language that you go to when you want to optimize something is almost the exact same syntax, it's Java. If you're working in the Ruby or Python worlds, you're going to have to go to either C which is a big shift or Java, which is also quite different than those languages. Programming in Groovy tends to help keep your Java skills somewhat sharp as well.

If you have particular access to a Ruby or Python infrastructure, or a team that has familiarity with those kind of environments, then I could see choosing one of those other languages.

Really, all 3 of them are very nice languages and what you pick should depend more on the problem that you're trying to fix and the resources that you have available to you. Once you've become proficient in one dynamic language, picking up a second or a third is much easier.

This video can help you solving your question :)
By: admin