<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Multiple Image Uploads Into Single MySQL Table (CakePHP)</title>
	<atom:link href="http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/feed/" rel="self" type="application/rss+xml" />
	<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/</link>
	<description>I break it. I fix it. You learn.</description>
	<lastBuildDate>Tue, 13 Jul 2010 11:10:57 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: Kim</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-232</link>
		<dc:creator>Kim</dc:creator>
		<pubDate>Thu, 11 Sep 2008 15:05:52 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-232</guid>
		<description>Hi there

I&#039;ve used the single image upload code, but I get the following error 

Notice: Undefined variable: write in cake/app/controllers/components/upload.php on line 286

Warning: unlink(/cake/app/webroot/img/uploads/) [function.unlink]: Is a directory in cake/app/controllers/images_controller.php on line 42

I&#039;m new to cake and php, but I think the $write variable hasn&#039;t been defined.

Please help

Thanks</description>
		<content:encoded><![CDATA[<p>Hi there</p>
<p>I&#8217;ve used the single image upload code, but I get the following error </p>
<p>Notice: Undefined variable: write in cake/app/controllers/components/upload.php on line 286</p>
<p>Warning: unlink(/cake/app/webroot/img/uploads/) [function.unlink]: Is a directory in cake/app/controllers/images_controller.php on line 42</p>
<p>I&#8217;m new to cake and php, but I think the $write variable hasn&#8217;t been defined.</p>
<p>Please help</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Boris</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-180</link>
		<dc:creator>Boris</dc:creator>
		<pubDate>Mon, 14 Jul 2008 12:12:16 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-180</guid>
		<description>Your code kind of sucks, why use a fixed amount of file-uploads in combination with a manual numbering?

You could more easier use a array for storing multiple file-uploads. So instead of using &lt;code&gt;$html-&gt;file&lt;/code&gt; (or &lt;code&gt;$form-&gt;file&lt;/code&gt; in cake 1.2), create a custom  element:
&lt;pre&gt;&lt;code&gt;
&lt;?php for($x=0;$x
&lt;/code&gt;&lt;/pre&gt;

In the controller you can use:
&lt;pre&gt;&lt;code&gt;
data[image] as $image) {
   $this-&gt;Image-&gt;create();
   $this-&gt;Image-&gt;save($image);
}
?&gt;
&lt;/code&gt;&lt;/pre&gt;
Consider the controller code pseudo, since the array does not yet have the required structure for a valid insert into our Image table. Also there is no file handling implemented yet.</description>
		<content:encoded><![CDATA[<p>Your code kind of sucks, why use a fixed amount of file-uploads in combination with a manual numbering?</p>
<p>You could more easier use a array for storing multiple file-uploads. So instead of using <code>$html->file</code> (or <code>$form->file</code> in cake 1.2), create a custom  element:</p>
<pre><code>
< ?php for($x=0;$x
</code></code></pre>
<p>In the controller you can use:</p>
<pre><code>
data[image] as $image) {
   $this-&gt;Image-&gt;create();
   $this-&gt;Image-&gt;save($image);
}
?>
</code></pre>
<p>Consider the controller code pseudo, since the array does not yet have the required structure for a valid insert into our Image table. Also there is no file handling implemented yet.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Suganya</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-147</link>
		<dc:creator>Suganya</dc:creator>
		<pubDate>Mon, 05 May 2008 12:06:11 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-147</guid>
		<description>When i download and execute this code im getting this error....


Class &#039;AppController&#039; not found in C:\wamp\www\multipleimage\multiple-uploads-11062007\app\controllers\images_controller.php on line 2


Send me a reply and send this function</description>
		<content:encoded><![CDATA[<p>When i download and execute this code im getting this error&#8230;.</p>
<p>Class &#8216;AppController&#8217; not found in C:\wamp\www\multipleimage\multiple-uploads-11062007\app\controllers\images_controller.php on line 2</p>
<p>Send me a reply and send this function</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mus</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-135</link>
		<dc:creator>mus</dc:creator>
		<pubDate>Thu, 17 Apr 2008 20:18:36 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-135</guid>
		<description>If you want multiple sql records for each images try this:

Remove the implode array line and then do a foreach, 

very important to set the id to null or in each loop it will overwrite the date from the previous one and only add the last one.
&lt;pre&gt;&lt;code&gt;
if (!empty($array)){
	//save the data
								
	foreach ($array as $value) {
		$this-&gt;Image-&gt;id = null;
		$this-&gt;data[&#039;Image&#039;][&#039;images&#039;] = $value;
		$this-&gt;Image-&gt;save($this-&gt;data);
	}	
					
} else {
	$this-&gt;Session-&gt;setFlash(&#039;No images have been uploaded!&#039;);
	$this-&gt;redirect(&#039;/images/index&#039;);
	exit();
}
				
$this-&gt;redirect(&#039;/images/index&#039;);
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>If you want multiple sql records for each images try this:</p>
<p>Remove the implode array line and then do a foreach, </p>
<p>very important to set the id to null or in each loop it will overwrite the date from the previous one and only add the last one.</p>
<pre><code>
if (!empty($array)){
	//save the data

	foreach ($array as $value) {
		$this->Image->id = null;
		$this->data['Image']['images'] = $value;
		$this->Image->save($this->data);
	}	

} else {
	$this->Session->setFlash('No images have been uploaded!');
	$this->redirect('/images/index');
	exit();
}

$this->redirect('/images/index');
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: venkat</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-121</link>
		<dc:creator>venkat</dc:creator>
		<pubDate>Mon, 17 Mar 2008 11:02:35 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-121</guid>
		<description>very nice</description>
		<content:encoded><![CDATA[<p>very nice</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Eric</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-110</link>
		<dc:creator>Eric</dc:creator>
		<pubDate>Fri, 29 Feb 2008 22:13:53 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-110</guid>
		<description>Hi,

First off, thanks for posting these components. I removed a bunch of the code so I could use them for general file uploads rather then just images. 

I ran into a few things on the way I thought I should share.
The &lt;code&gt;upload()&lt;/code&gt; function does not always return true or false depending on if the upload succeeds. This is important because in the code the $result is relied on in the image controller. I moved some things around, but at the bottom of the function I added this line which should take care of the issue:
&lt;pre&gt;&lt;code&gt;
// if no errors, then return true
return $this-&gt;error === false ? true : false ;
&lt;/code&gt;&lt;/pre&gt;
Also in the upload function, you go through the effort of adding an ending slash to the &lt;code&gt;$directory&lt;/code&gt; variable being passed in, and assign it to &lt;code&gt;$this-&gt;_destination&lt;/code&gt;. However, a few lines later when you need to use the slash appended directory, you use the &lt;code&gt;$directory&lt;/code&gt; variable again rather then the freshly appended &lt;code&gt;$this-&gt;_destination&lt;/code&gt;
&lt;pre&gt;&lt;code&gt;
$fileName = ($name == NULL) ? $this-&gt;uniquename($this-&gt;_destination......
&lt;/code&gt;&lt;/pre&gt;
The last thing I found, this may not be a big issue for some people, but in the uniquename function, and in the upload function, you hard code the &quot;/&quot; to separate directories. This is not a problem if you are on *nix, but windows has a problem with this. To get around this problem, just replace the slash with PHP constant DIRECTORY_SEPARATOR.

Thanks again for the work!</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>First off, thanks for posting these components. I removed a bunch of the code so I could use them for general file uploads rather then just images. </p>
<p>I ran into a few things on the way I thought I should share.<br />
The <code>upload()</code> function does not always return true or false depending on if the upload succeeds. This is important because in the code the $result is relied on in the image controller. I moved some things around, but at the bottom of the function I added this line which should take care of the issue:</p>
<pre><code>
// if no errors, then return true
return $this->error === false ? true : false ;
</code></pre>
<p>Also in the upload function, you go through the effort of adding an ending slash to the <code>$directory</code> variable being passed in, and assign it to <code>$this->_destination</code>. However, a few lines later when you need to use the slash appended directory, you use the <code>$directory</code> variable again rather then the freshly appended <code>$this->_destination</code></p>
<pre><code>
$fileName = ($name == NULL) ? $this->uniquename($this->_destination......
</code></pre>
<p>The last thing I found, this may not be a big issue for some people, but in the uniquename function, and in the upload function, you hard code the &#8220;/&#8221; to separate directories. This is not a problem if you are on *nix, but windows has a problem with this. To get around this problem, just replace the slash with PHP constant DIRECTORY_SEPARATOR.</p>
<p>Thanks again for the work!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Livetoday</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-106</link>
		<dc:creator>Livetoday</dc:creator>
		<pubDate>Sat, 16 Feb 2008 08:29:05 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-106</guid>
		<description>Releod, that worked for me ;O)
&lt;pre&gt;&lt;code&gt;
foreach($array as $arr):
   $this-&gt;Image-&gt;query(&quot;INSERT INTO images(id,imgSrc) VALUES(NULL,&quot;&#039;.$arr.&#039;&quot;)&quot;);
endforeach;
&lt;/code&gt;&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>Releod, that worked for me ;O)</p>
<pre><code>
foreach($array as $arr):
   $this->Image->query("INSERT INTO images(id,imgSrc) VALUES(NULL,"'.$arr.'")");
endforeach;
</code></pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: CakePHP 1.1 File Upload Plays Rough With PHP 4 - Labs</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-47</link>
		<dc:creator>CakePHP 1.1 File Upload Plays Rough With PHP 4 - Labs</dc:creator>
		<pubDate>Wed, 12 Dec 2007 00:23:11 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-47</guid>
		<description>[...] files via CakePHP has been covered a few times on Labs. Based on the feedback, it&#8217;s safe to assume bridging the gap between file [...]</description>
		<content:encoded><![CDATA[<p>[...] files via CakePHP has been covered a few times on Labs. Based on the feedback, it&#8217;s safe to assume bridging the gap between file [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: releod</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-36</link>
		<dc:creator>releod</dc:creator>
		<pubDate>Tue, 20 Nov 2007 18:25:59 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-36</guid>
		<description>I totally agree with the comment above, would love to see this adding its own record for each file upload, instead of imploding them all into the same record.

Great work though.</description>
		<content:encoded><![CDATA[<p>I totally agree with the comment above, would love to see this adding its own record for each file upload, instead of imploding them all into the same record.</p>
<p>Great work though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Moelle</title>
		<link>http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/comment-page-1/#comment-28</link>
		<dc:creator>Moelle</dc:creator>
		<pubDate>Sat, 10 Nov 2007 12:41:56 +0000</pubDate>
		<guid isPermaLink="false">http://labs.iamkoa.net/2007/11/06/multiple-image-uploads-into-single-mysql-table-cakephp/#comment-28</guid>
		<description>So the multiple upload works GREAT but it would be better for me if each image had it&#039;s own record in MySQL instead of one recorde with multiple images. I tried it myself to modify the controller but i couldn&#039;t get it to work. Can you help me with that?</description>
		<content:encoded><![CDATA[<p>So the multiple upload works GREAT but it would be better for me if each image had it&#8217;s own record in MySQL instead of one recorde with multiple images. I tried it myself to modify the controller but i couldn&#8217;t get it to work. Can you help me with that?</p>
]]></content:encoded>
	</item>
</channel>
</rss>
