<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jefim Borissov &#187; codeigniter upload</title>
	<atom:link href="http://jefim.eu/blog/tag/codeigniter-upload/feed/" rel="self" type="application/rss+xml" />
	<link>http://jefim.eu/blog</link>
	<description>Житие мое</description>
	<lastBuildDate>Fri, 05 Aug 2011 22:28:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.3</generator>
		<item>
		<title>Image / file upload with CodeIgniter</title>
		<link>http://jefim.eu/blog/2009/10/image-file-upload-with-codeigniter/</link>
		<comments>http://jefim.eu/blog/2009/10/image-file-upload-with-codeigniter/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 11:15:42 +0000</pubDate>
		<dc:creator>Jefim</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[codeigniter upload]]></category>

		<guid isPermaLink="false">http://jefim.eu/blog/?p=239</guid>
		<description><![CDATA[Image upload can be a pain in the *ss. And even though CI has a lot to offer (in the means of documentation) it still lacks a direct copy-paste code on their website so that people can just put it into their controller and use away. Here we will have: Image upload form with 5 [...]]]></description>
			<content:encoded><![CDATA[<p>Image upload can be a pain in the *ss. And even though CI has a lot to offer (in the means of documentation) it still lacks a direct copy-paste code on their website so that people can just put it into their controller and use away.<br />
Here we will have:</p>
<ul>
<li>Image upload form with 5 images</li>
<li>And a controller function that will upload those</li>
<li>Thumbnails will be there too <img src='http://jefim.eu/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
</ul>
<p><span id="more-239"></span>Ok, lets start with the HTML form code, it is very basic:<br />
<strong>views/upload_form.php</strong></p>
<pre name="code" class="html">
&lt;form method="post" action="uploader/go" enctype="multipart/form-data"&gt;
  &lt;input type="file" name="image1" /&gt;&lt;br /&gt;
  &lt;input type="file" name="image2" /&gt;&lt;br /&gt;
  &lt;input type="file" name="image3" /&gt;&lt;br /&gt;
  &lt;input type="file" name="image4" /&gt;&lt;br /&gt;
  &lt;input type="file" name="image5" /&gt;&lt;br /&gt;
  &lt;input type="submit" name="go" value="Upload!!!" /&gt;
&lt;/form&gt;
</pre>
<p>And now the controller:<br />
<strong>controllers/Uploader.php</strong></p>
<pre name="code" class="php">
class Uploader extends Controller {
  function go() {
    if(isset($_POST['go'])) {
      /* Create the config for upload library */
      /* (pretty self-explanatory) */
      $config['upload_path'] = './assets/upload/'; /* NB! create this dir! */
      $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
      $config['max_size']  = '0';
      $config['max_width']  = '0';
      $config['max_height']  = '0';
      /* Load the upload library */
      $this->load->library('upload', $config);

      /* Create the config for image library */
      /* (pretty self-explanatory) */
      $configThumb = array();
      $configThumb['image_library'] = 'gd2';
      $configThumb['source_image'] = '';
      $configThumb['create_thumb'] = TRUE;
      $configThumb['maintain_ratio'] = TRUE;
      /* Set the height and width or thumbs */
      /* Do not worry - CI is pretty smart in resizing */
      /* It will create the largest thumb that can fit in those dimensions */
      /* Thumbs will be saved in same upload dir but with a _thumb suffix */
      /* e.g. 'image.jpg' thumb would be called 'image_thumb.jpg' */
      $configThumb['width'] = 140;
      $configThumb['height'] = 210;
      /* Load the image library */
      $this->load->library('image_lib');

      /* We have 5 files to upload
       * If you want more - change the 6 below as needed
       */
      for($i = 1; $i < 6; $i++) {
        /* Handle the file upload */
        $upload = $this->upload->do_upload('image'.$i);
        /* File failed to upload - continue */
        if($upload === FALSE) continue;
        /* Get the data about the file */
        $data = $this->upload->data();

        $uploadedFiles[$i] = $data;
        /* If the file is an image - create a thumbnail */
        if($data['is_image'] == 1) {
          $configThumb['source_image'] = $data['full_path'];
          $this->image_lib->initialize($configThumb);
          $this->image_lib->resize();
        }
      }
    }
    /* And display the form again */
    $this->load->view('upload_form');
  }
}
</pre>
<p>And that is it. Customize it to your needs, the basics are there already. And good luck!</p>
]]></content:encoded>
			<wfw:commentRss>http://jefim.eu/blog/2009/10/image-file-upload-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
	</channel>
</rss>

