<?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>0t@k-B@L! &#187; trick</title>
	<atom:link href="http://www.otakbali.com/tag/trick/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.otakbali.com</link>
	<description>think about web programming</description>
	<lastBuildDate>Mon, 02 Aug 2010 03:56:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Display Images from mySQL Binary Data</title>
		<link>http://www.otakbali.com/display-images-from-mysql-binary-data.html</link>
		<comments>http://www.otakbali.com/display-images-from-mysql-binary-data.html#comments</comments>
		<pubDate>Tue, 10 Nov 2009 15:11:14 +0000</pubDate>
		<dc:creator>andi</dc:creator>
				<category><![CDATA[Tips n Trik]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://otakbali.com/?p=63</guid>
		<description><![CDATA[This tutorial will show you how to display your images (binary data) which has been saved in your mySQL database. It&#8217;s very very simple.. so.. simple&#8230;. (read also: Storing Images/Binary Files to mySQL in PHP) First of all we must connect to our database PHP Code: &#60;?php $username = ""; $password = ""; $host = [...]]]></description>
			<content:encoded><![CDATA[<div id="post_message_41500">This tutorial will show you how to display your images (binary data) which has been saved in your mySQL database.</div>
<div>It&#8217;s very very  simple.. so.. simple&#8230;. (read also: <a href="http://otakbali.com/storing-imagesbinary-files-to-mysql-in-php/"><strong>Storing Images/Binary Files to mySQL in PHP</strong></a>)</p>
<p>First of all we must connect to our database</p></div>
<div id="post_message_41500">
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 114px; text-align: left;" dir="ltr"><code><span style="color: #000000;"><span style="color: #0000bb;">&lt;?php<br />
$username </span><span style="color: #007700;">= </span><span style="color: #dd0000;">""</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$password </span><span style="color: #007700;">= </span><span style="color: #dd0000;">""</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$host </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"localhost"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$database </span><span style="color: #007700;">= </span><span style="color: #dd0000;">""</span><span style="color: #007700;">;</span></p>
<p></span></code></div>
</div>
<p><strong><span id="more-63"></span>$username = &#8220;&#8221;;</strong> &#8211; It&#8217;s your database&#8217;s username<strong><br />
$password = &#8220;&#8221;;</strong> &#8211; It&#8217;s your database&#8217;s password<strong><br />
$host = &#8220;localhost&#8221;;</strong> &#8211; It&#8217;s your database&#8217;s host, usually it&#8217;s localhost but it can be something else also<strong><br />
$database = &#8220;&#8221;;</strong> &#8211; It&#8217;s your database</p>
<p>Now let&#8217;s connect to the database</p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 66px; text-align: left;" dir="ltr"><code><span style="color: #000000;"><span style="color: #0000bb;"> </span><span style="color: #007700;">@</span><span style="color: #0000bb;">mysql_connect</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$host</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$username</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$password</span><span style="color: #007700;">) or die(</span><span style="color: #dd0000;">"Can not connect to database: "</span><span style="color: #007700;">.</span><span style="color: #0000bb;">mysql_error</span><span style="color: #007700;">());<br />
@</span><span style="color: #0000bb;">mysql_select_db</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$database</span><span style="color: #007700;">) or die(</span><span style="color: #dd0000;">"Can not select the database: "</span><span style="color: #007700;">.</span><span style="color: #0000bb;">mysql_error</span><span style="color: #007700;">()); </span></p>
<p></span><span style="color: #0000bb;"> </span></code></div>
</div>
<p><strong>@mysql_connect($host, $username, $password) or die(&#8220;Can not connect to database:&#8221;.mysql_error());</strong> &#8211; This connects to your database<br />
<strong><br />
@mysql_select_db($database) or die(&#8220;Can not select the database: &#8220;.mysql_error());</strong> &#8211; This will select your database</p>
<p>Now let&#8217;s get our id</p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 34px; text-align: left;" dir="ltr"><code><span style="color: #000000;"><span style="color: #0000bb;">$id </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$_GET</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'id'</span><span style="color: #007700;">]; </span><span style="color: #0000bb;"> </span></span></code></div>
</div>
<p>It will get a id from an URL. <a href="http://blabla.com" target="_blank">blabla.com</a></p>
<p>So.. your id will be 3 and it will show an image which id is 3</p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 66px; text-align: left;" dir="ltr"><code><span style="color: #000000;"><span style="color: #0000bb;"> </span><span style="color: #007700;">if(!isset(</span><span style="color: #0000bb;">$id</span><span style="color: #007700;">) || empty(</span><span style="color: #0000bb;">$id</span><span style="color: #007700;">)){<br />
die(</span><span style="color: #dd0000;">"Please select your image!"</span><span style="color: #007700;">);<br />
}else{</span></span></code></div>
</div>
<p><strong>if(!isset($id) || empty($id)){</strong> &#8211; If this ID in your url is empty like <em>?id=</em> of if it&#8217;s not even set<strong><br />
die(&#8220;Please select your image!&#8221;);</strong> &#8211; lets display an error<strong><br />
}else{</strong> &#8211; But if it is set let&#8217;s continue with showing our image</p>
<p><img class="tcattdimgresizer" src="http://forum.codecall.net/images/Tutorials/jaan/5x0vq0.jpg" border="0" alt="" /></p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 66px; text-align: left;" dir="ltr"><code style="white-space: nowrap;"><br />
<!-- php buffer start --></code><code><span style="color: #000000;"><span style="color: #0000bb;">$query </span><span style="color: #007700;">= </span><span style="color: #0000bb;">mysql_query</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"SELECT * FROM tbl_images WHERE id='"</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$id</span><span style="color: #007700;">.</span><span style="color: #dd0000;">"'"</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$row </span><span style="color: #007700;">= </span><span style="color: #0000bb;">mysql_fetch_array</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$content </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$row</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'image'</span><span style="color: #007700;">]; </span></p>
<p></span></code></div>
</div>
<p><strong>$query = mysql_query(&#8220;SELECT * FROM tbl_images WHERE id=&#8217;&#8221;.$id.&#8221;&#8216;&#8221;);</strong> &#8211; Now let&#8217;s select the blob from the table where id is $id (for example: 3)</p>
<p><strong>$row = mysql_fetch_array($query);</strong> &#8211; Let&#8217;s gather our info about image which id is $id into one variable</p>
<p><strong>$content = $row['image'];</strong> &#8211; Get&#8217;s the blob from our table<br />
Now let&#8217;s display our image</p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 82px; text-align: left;" dir="ltr"><code><span style="color: #000000;"><span style="color: #0000bb;">header</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Content-type: image/jpg'</span><span style="color: #007700;">);<br />
echo </span><span style="color: #0000bb;">$content</span><span style="color: #007700;">;<br />
} </span></span></code></div>
</div>
<p><strong>header(&#8216;Content-type: image/jpg&#8217;);</strong> &#8211; This tells to the browser and to the server that this file will be a jpg file</p>
<p><strong>echo $content;</strong> &#8211; This will display our blob..</p>
<p><strong>}</strong> &#8211; Ends else<br />
Okay.. now here&#8217;s our full script.</p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 450px; text-align: left;" dir="ltr"><code><span style="color: #000000;"><span style="color: #0000bb;">&lt;?php</p>
<p>$username</p>
<p></span><span style="color: #007700;">= </span><span style="color: #dd0000;">""</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$password </span><span style="color: #007700;">= </span><span style="color: #dd0000;">""</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$host </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"localhost"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$database </span><span style="color: #007700;">= </span><span style="color: #dd0000;">""</span><span style="color: #007700;">;</p>
<p>@</p>
<p></span><span style="color: #0000bb;">mysql_connect</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$host</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$username</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$password</span><span style="color: #007700;">) or die(</span><span style="color: #dd0000;">"Can not connect to database: "</span><span style="color: #007700;">.</span><span style="color: #0000bb;">mysql_error</span><span style="color: #007700;">());</p>
<p>@</p>
<p></span><span style="color: #0000bb;">mysql_select_db</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$database</span><span style="color: #007700;">) or die(</span><span style="color: #dd0000;">"Can not select the database: "</span><span style="color: #007700;">.</span><span style="color: #0000bb;">mysql_error</span><span style="color: #007700;">());</p>
<p></span><span style="color: #0000bb;">$id </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$_GET</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'id'</span><span style="color: #007700;">];</p>
<p>if(!isset(</p>
<p></span><span style="color: #0000bb;">$id</span><span style="color: #007700;">) || empty(</span><span style="color: #0000bb;">$id</span><span style="color: #007700;">)){<br />
die(</span><span style="color: #dd0000;">"Please select your image!"</span><span style="color: #007700;">);<br />
}else{</p>
<p></span><span style="color: #0000bb;">$query </span><span style="color: #007700;">= </span><span style="color: #0000bb;">mysql_query</span><span style="color: #007700;">(</span><span style="color: #dd0000;">"SELECT * FROM tbl_images WHERE id='"</span><span style="color: #007700;">.</span><span style="color: #0000bb;">$id</span><span style="color: #007700;">.</span><span style="color: #dd0000;">"'"</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$row </span><span style="color: #007700;">= </span><span style="color: #0000bb;">mysql_fetch_array</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$content </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$row</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'image'</span><span style="color: #007700;">];</p>
<p></span><span style="color: #0000bb;">header</span><span style="color: #007700;">(</span><span style="color: #dd0000;">'Content-type: image/jpg'</span><span style="color: #007700;">);<br />
echo </span><span style="color: #0000bb;">$content</span><span style="color: #007700;">;</p>
<p>}</p>
<p></span><span style="color: #0000bb;">?&gt;</span></span> </code><!-- php buffer end --></div>
</div>
<p>It works perfectly</p>
<p><img class="tcattdimgresizer" src="http://forum.codecall.net/images/Tutorials/jaan/ingvvq.jpg" border="0" alt="" /></p>
<p>Enjoy&#8230; <img src='http://www.otakbali.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />      If you have questions then please feel free to ask</div>
]]></content:encoded>
			<wfw:commentRss>http://www.otakbali.com/display-images-from-mysql-binary-data.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Storing Images/Binary Files to mySQL in PHP</title>
		<link>http://www.otakbali.com/storing-imagesbinary-files-to-mysql-in-php.html</link>
		<comments>http://www.otakbali.com/storing-imagesbinary-files-to-mysql-in-php.html#comments</comments>
		<pubDate>Tue, 10 Nov 2009 13:58:06 +0000</pubDate>
		<dc:creator>andi</dc:creator>
				<category><![CDATA[Tips n Trik]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://otakbali.com/?p=59</guid>
		<description><![CDATA[how to store images, audio, or another binary files into mySQL database with PHP script. cara menyimpan gambar ke mysql dengan PHP.]]></description>
			<content:encoded><![CDATA[<p>It is possible for us to store/save our images (binary files) into a mySQL database in PHP. In this article, we will discuss about &#8220;how to store images, audio, or another binary files into mySQL database with PHP script&#8221;. But, before we continue to the further step, you might want to consider some reason of why we should and why we shouldn&#8217;t store binary files in a database:</p>
<p>Reasons to store your images (binary files) in a database:</p>
<ol style="list-style-type: decimal;">
<li>Storing in a database allows better security for your files and images.</li>
<li>Eliminates messy directory and file structures (this is especially true when users are allow to contribute files).</li>
<li>Files/Images can be stored directly linking to user or advertiser information.<span id="more-59"></span></li>
</ol>
<p>You may want to reconsider storing your binary files in the database.  Here are some reason you may not want to:</p>
<ol style="list-style-type: decimal;">
<li>You can&#8217;t directly access your files using standard applications such as FTP.</li>
<li>If you database becomes corrupt, so do your files.</li>
<li>Migrating to a new database is made more difficult</li>
<li>Pulling images from a database and displaying them is slower than using file access.</li>
</ol>
<p>After considering above reasons, you may continue to the first step of this tutorial.</p>
<p><span style="font-size: medium;">Database Type and Connection</span></p>
<p>I assume that you already create a mySQL database named &#8220;binary&#8221;. We created two tables, one the primary ID (of the row/entry) and the binary BLOB. A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements.</p>
<p>You&#8217;ve now created your database and are ready to upload binary files to it. In this case, images. Next we will create a simple upload script.</p>
<p><span style="font-size: medium;">Creating the HTML</span></p>
<p>Creating the user interface where you or your visitors will upload files is very simple.  Using basic HTML and relying on the browser to do most of the heavy lifting you can easily create an upload form.  Here is the one we will use:</p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">HTML Code:</div>
<pre class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 82px; text-align: left;" dir="ltr"><span style="color: #ff8000;">&lt;form enctype=<span style="color: #0000ff;">"multipart/form-data"</span> action=<span style="color: #0000ff;">"insert.php"</span> method=<span style="color: #0000ff;">"post"</span> name=<span style="color: #0000ff;">"changer"</span>&gt;</span>

<span style="color: #ff8000;">&lt;input name=<span style="color: #0000ff;">"MAX_FILE_SIZE"</span> value=<span style="color: #0000ff;">"102400"</span> type=<span style="color: #0000ff;">"hidden"</span>&gt;</span>
<span style="color: #ff8000;">&lt;input name=<span style="color: #0000ff;">"image"</span> accept=<span style="color: #0000ff;">"image/jpeg"</span> type=<span style="color: #0000ff;">"file"</span>&gt;</span>

<span style="color: #ff8000;">&lt;input value=<span style="color: #0000ff;">"Submit"</span> type=<span style="color: #0000ff;">"submit"</span>&gt;</span></pre>
</div>
<p>Copy this code into a file and save it as <strong>add.html</strong></p>
<p>The code above allows the uses to browse for a file and select any image/jpeg file type.   Once selected and the submit button is pressed the image contents are forwarded to PHP script, <strong>insert.php</strong></p>
<p><span style="font-size: medium;"><strong>Inserting the Image into MySQL</strong></span></p>
<p>Create a new file named insert.php.  If you change the name of this file you will also need to change the action=&#8221;" part in your HTML file above.  Open the file in your favorite text editor or PHP IDE.</p>
<p>Write or copy/paste this code into your file:</p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 274px; text-align: left;" dir="ltr"><code style="white-space: nowrap;"><br />
<!-- php buffer start --></code><code><span style="color: #000000;"><br />
<span style="color: #0000bb;"> </span><span style="color: #ff8000;">// Create MySQL login values and<br />
// set them to your login information.<br />
</span><span style="color: #0000bb;">$username </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"YourUserName"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$password </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"YourPassword"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$host </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"localhost"</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$database </span><span style="color: #007700;">= </span><span style="color: #dd0000;">"binary"</span><span style="color: #007700;">;</p>
<p></span><span style="color: #ff8000;">// Make the connect to MySQL or die<br />
// and display an error.<br />
</span><span style="color: #0000bb;">$link </span><span style="color: #007700;">= </span><span style="color: #0000bb;">mysql_connect</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$host</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$username</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$password</span><span style="color: #007700;">);<br />
if (!</span><span style="color: #0000bb;">$link</span><span style="color: #007700;">) {<br />
die(</span><span style="color: #dd0000;">'Could not connect: ' </span><span style="color: #007700;">. </span><span style="color: #0000bb;">mysql_error</span><span style="color: #007700;">());<br />
}</p>
<p></span><span style="color: #ff8000;">// Select your database<br />
</span><span style="color: #0000bb;">mysql_select_db </span><span style="color: #007700;">(</span><span style="color: #0000bb;">$database</span><span style="color: #007700;">);</p>
<p></span><span style="color: #0000bb;"> </span><br />
</span><br />
</code><!-- php buffer end --></div>
</div>
<p>The above code sets your connection variables, creates a connection to MySQL and selects your database (binary if you followed my instructions above).  Next we need to read the form data and insert it into the database.</p>
<div style="margin: 5px 20px 20px;">
<div class="smallfont" style="margin-bottom: 2px;">PHP Code:</div>
<div class="alt2" style="border: 1px inset; margin: 0px; padding: 6px; overflow: auto; width: 500px; height: 498px; text-align: left;" dir="ltr">
<p><code style="white-space: nowrap;"><br />
<!-- php buffer start --></code><code><span style="color: #000000;"><br />
<span style="color: #0000bb;"> </span><span style="color: #ff8000;">// Make sure the user actually<br />
// selected and uploaded a file<br />
</span><span style="color: #007700;">if (isset(</span><span style="color: #0000bb;">$_FILES</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'image'</span><span style="color: #007700;">]) &amp;&amp; </span><span style="color: #0000bb;">$_FILES</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'image'</span><span style="color: #007700;">][</span><span style="color: #dd0000;">'size'</span><span style="color: #007700;">] &gt; </span><span style="color: #0000bb;">0</span><span style="color: #007700;">) {</span></span></code></p>
<p><span style="color: #ff8000;">// Temporary file name stored on the server<br />
</span><span style="color: #0000bb;">$tmpName </span><span style="color: #007700;">= </span><span style="color: #0000bb;">$_FILES</span><span style="color: #007700;">[</span><span style="color: #dd0000;">'image'</span><span style="color: #007700;">][</span><span style="color: #dd0000;">'tmp_name'</span><span style="color: #007700;">];</span></p>
<p><span style="color: #ff8000;">// Read the file<br />
</span><span style="color: #0000bb;">$fp </span><span style="color: #007700;">= </span><span style="color: #0000bb;">fopen</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$tmpName</span><span style="color: #007700;">, </span><span style="color: #dd0000;">&#8216;r&#8217;</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">$data </span><span style="color: #007700;">= </span><span style="color: #0000bb;">fread</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$fp</span><span style="color: #007700;">, </span><span style="color: #0000bb;">filesize</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$tmpName</span><span style="color: #007700;">));<br />
</span><span style="color: #0000bb;">$data </span><span style="color: #007700;">= </span><span style="color: #0000bb;">addslashes</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$data</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">fclose</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$fp</span><span style="color: #007700;">);</span></p>
<p><span style="color: #ff8000;">// Create the query and insert<br />
// into our database.<br />
</span><span style="color: #0000bb;">$query </span><span style="color: #007700;">= </span><span style="color: #dd0000;">&#8220;INSERT INTO tbl_images &#8221;</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$query </span><span style="color: #007700;">.= </span><span style="color: #dd0000;">&#8220;(image) VALUES (&#8216;$data&#8217;)&#8221;</span><span style="color: #007700;">;<br />
</span><span style="color: #0000bb;">$results </span><span style="color: #007700;">= </span><span style="color: #0000bb;">mysql_query</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$query</span><span style="color: #007700;">, </span><span style="color: #0000bb;">$link</span><span style="color: #007700;">);</span></p>
<p><span style="color: #ff8000;">// Print results<br />
</span><span style="color: #007700;">print </span><span style="color: #dd0000;">&#8220;Thank you, your file has been uploaded.&#8221;</span><span style="color: #007700;">;</span></p>
<p>}<br />
else {<br />
print <span style="color: #dd0000;">&#8220;No image selected/uploaded&#8221;</span><span style="color: #007700;">;<br />
}</span></p>
<p><span style="color: #ff8000;">// Close our MySQL Link<br />
</span><span style="color: #0000bb;">mysql_close</span><span style="color: #007700;">(</span><span style="color: #0000bb;">$link</span><span style="color: #007700;">);<br />
</span><span style="color: #0000bb;">?&gt;</span></p>
<p><!-- php buffer end --></div>
</div>
<p>The PHP code above takes the user selected image, reads it with fopen and stores the data in a variable named $data.  The binary data is then inserted into our database for retrieval at a later time.</p>
<p>Save the file above and access add.html via your browser.  Select an image file and upload it.</p>
<p>I will post the next stage of this tutorial: &#8220;<a href="http://otakbali.com/display Images-from-mySQL-binary-data"><strong>How to read binary data from database</strong></a>&#8220;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.otakbali.com/storing-imagesbinary-files-to-mysql-in-php.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>.htaccess Tricks: #1 &#8211; Definition</title>
		<link>http://www.otakbali.com/htaccess-tricks-1-definition.html</link>
		<comments>http://www.otakbali.com/htaccess-tricks-1-definition.html#comments</comments>
		<pubDate>Wed, 28 Oct 2009 15:29:26 +0000</pubDate>
		<dc:creator>andi</dc:creator>
				<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[Tips n Trik]]></category>
		<category><![CDATA[programmer]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://otakbali.com/?p=48</guid>
		<description><![CDATA[.htaccess definition: Apache server software provides distributed (i.e., directory-level) configuration via Hypertext Access files. These .htaccess files enable the localized fine-tuning of Apache’s universal system-configuration directives, which are defined in Apache’s main configuration file. The localized .htaccess directives must operate from within a file named .htaccess. The user must have appropriate file permissions to access [...]]]></description>
			<content:encoded><![CDATA[<p><a name="top"></a></p>
<div class="wp-caption alignleft" style="width: 190px"><a href="http://otakbali.com/tag/htaccess"><img class=" " title=".htaccess in otakbali" src="http://i720.photobucket.com/albums/ww207/andiim3/otakbali_htaccess.gif" alt=".htaccess Tips n Trick" width="180" height="180" /></a><p class="wp-caption-text">.htaccess Tips n Trick</p></div>
<p style="text-align: justify;"><strong><code>.htaccess</code> definition: </strong><br />
Apache server software provides distributed (i.e., directory-level) configuration via Hypertext Access files. These <a title="htaccess at Wikipedia" rel="nofollow" href="http://en.wikipedia.org/wiki/Htaccess"><code>.</code><code>htaccess</code></a> files enable the localized fine-tuning of Apache’s universal system-configuration directives, which are defined in Apache’s main configuration file. The localized <code>.</code><code>htaccess</code> directives must operate from within a file named <code>.</code><code>htaccess</code>. The user must have appropriate file permissions to access and/or edit the <code>.</code><code>htaccess</code> file. Further, <code>.</code><code>htaccess</code> file permissions should never allow world write access — a secure permissions setting is “644”, which allows universal read access and user-only write access. Finally, <code>.</code><code>htaccess</code> rules apply to the parent directory and all subdirectories. Thus to apply configuration rules to an entire website, place the <code>.</code><code>htaccess</code> file in the root directory of the site.<br />
<span id="more-48"></span></p>
<p style="text-align: justify;"><strong>Comments on <code>.htaccess</code> code</strong><br />
Comments are essential to maintaining control over any involved portion of code. Comments in <code>.</code><code>htaccess</code> code are fashioned on a per-line basis, with each line of comments beginning with a pound sign <code>#</code>. Thus, comments spanning multiple lines in the <code>.</code><code>htaccess</code> file require multiple pound signs. Further, due to the extremely volatile nature of htaccess voodoo, it is wise to include only alphanumeric characters (and perhaps a few dashes and underscores) in any <code>.</code><code>htaccess</code> comments.</p>
<p><strong id="gen3">Important Notes for .</strong><strong>htaccess Noobs</strong> <small>[ <a href="#top">^</a> ]</small></p>
<p>As a configuration file, <code>.</code><code>htaccess</code> is very powerful. Even the slightest syntax error (like a missing space) can result in severe server malfunction. Thus it is crucial to make backup copies of <em>everything</em> related to your site (including any original <code>.</code><code>htaccess</code> files) <em>before</em> working with your Hypertext Access file(s). It is also important to check your entire website thoroughly after making any changes to your <code>.</code><code>htaccess</code> file. If any errors or other problems are encountered, employ your backups immediately to restore original functionality.</p>
<p><strong id="gen4">Performance Issues</strong> <small>[ <a href="#top">^</a> ]</small></p>
<p><code>.</code><code>htaccess</code> directives provide directory-level configuration without requiring access to Apache’s main server cofiguration file (httpd.conf). However, due to performance and security concerns, the main configuration file should always be used for server directives whenever possible. For example, when a server is configured to process <code>.</code><code>htaccess</code> directives, Apache must search every directory within the domain and load any and all <code>.</code><code>htaccess</code> files upon every document request. This results in increased page processing time and thus decreases performance. Such a performance hit may be unnoticeable for sites with light traffic, but becomes a more serious issue for more popular websites. Therefore, <code>.</code><code>htaccess</code> files should only be used when the main server configuration file is inaccessible. See the “<a href="\#performance">Performance Tricks</a>” section of this article for more information.</p>
<p><strong id="gen5">Regex Character Definitions for htaccess</strong><sup>2</sup> <small>[ <a href="#top">^</a> ]</small></p>
<dl>
<dt><code>#</code></dt>
<dd>the <code>#</code> instructs the server to ignore the line. used for including comments. each line of comments requires it’s own <code>#</code>. when including comments, it is good practice to use only letters, numbers, dashes, and underscores. this practice will help eliminate/avoid potential server parsing errors.</dd>
<dt><code>[F]</code></dt>
<dd>Forbidden: instructs the server to return a <code>403 Forbidden</code> to the client.</dd>
<dt><code>[L]</code></dt>
<dd>Last rule: instructs the server to stop rewriting after the preceding directive is processed.</dd>
<dt><code>[N]</code></dt>
<dd>Next: instructs Apache to rerun the rewrite rule until all rewriting directives have been achieved.</dd>
<dt><code>[G]</code></dt>
<dd>Gone: instructs the server to deliver <code>Gone (no longer exists)</code> status message.</dd>
<dt><code>[P]</code></dt>
<dd>Proxy: instructs server to handle requests by <code>mod_proxy</code></dd>
<dt><code>[C]</code></dt>
<dd>Chain: instructs server to chain the current rule with the previous rule.</dd>
<dt><code>[R]</code></dt>
<dd>Redirect: instructs Apache to issue a redirect, causing the browser to request the rewritten/modified URL.</dd>
<dt><code>[NC]</code></dt>
<dd>No Case: defines any associated argument as case-<em>in</em>sensitive. i.e., &#8220;NC&#8221; = &#8220;No Case&#8221;.</dd>
<dt><code>[PT]</code></dt>
<dd>Pass Through: instructs <code>mod_rewrite</code> to pass the rewritten URL back to Apache for further processing.</dd>
<dt><code>[OR]</code></dt>
<dd>Or: specifies a logical &#8220;or&#8221; that ties two expressions together such that either one proving true will cause the associated rule to be applied.</dd>
<dt><code>[NE]</code></dt>
<dd>No Escape: instructs the server to parse output without escaping characters.</dd>
<dt><code>[NS]</code></dt>
<dd>No Subrequest: instructs the server to skip the directive if internal sub-request.</dd>
<dt><code>[QSA]</code></dt>
<dd>Append Query String: directs server to add the query string to the end of the expression (URL).</dd>
<dt><code>[S=x]</code></dt>
<dd>Skip: instructs the server to skip the next &#8220;x&#8221; number of rules if a match is detected.</dd>
<dt><code>[E=variable:value]</code></dt>
<dd>Environmental Variable: instructs the server to set the environmental variable &#8220;variable&#8221; to &#8220;value&#8221;.</dd>
<dt><code>[T=MIME-type]</code></dt>
<dd>Mime Type: declares the mime type of the target resource.</dd>
<dt><code>[]</code></dt>
<dd>specifies a character class, in which any character within the brackets will be a match. e.g., [xyz] will match either an x, y, or z.</dd>
<dt><code>[]+</code></dt>
<dd>character class in which any combination of items within the brackets will be a match. e.g., [xyz]+ will match any number of x’s, y’s, z’s, or any combination of these characters.</dd>
<dt><code>[^]</code></dt>
<dd>specifies <em>not</em> within a character class. e.g., [^xyz] will match any character that is neither x, y, nor z.</dd>
<dt><code>[a-z]</code></dt>
<dd>a dash (-) between two characters within a character class ([]) denotes the range of characters between them. e.g., [a-zA-Z] matches all lowercase and uppercase letters from a to z.</dd>
<dt><code>a{n}</code></dt>
<dd>specifies an exact number, <code>n</code>, of the preceding character. e.g., x{3} matches exactly three <code>x</code>’s.</dd>
<dt><code>a{n,}</code></dt>
<dd>specifies <code>n</code> or more of the preceding character. e.g., x{3,} matches three or more <code>x</code>’s.</dd>
<dt><code>a{n,m}</code></dt>
<dd>specifies a range of numbers, between <code>n</code> and <code>m</code>, of the preceding character. e.g., x{3,7} matches three, four, five, six, or seven <code>x</code>’s.</dd>
<dt><code>()</code></dt>
<dd>used to group characters together, thereby considering them as a single unit. e.g., (perishable)?press will match press, with or without the perishable prefix.</dd>
<dt><code>^</code></dt>
<dd>denotes the beginning of a regex (regex = regular expression) test string. i.e., begin argument with the proceeding character.</dd>
<dt><code>$</code></dt>
<dd>denotes the end of a regex (regex = regular expression) test string. i.e., end argument with the previous character.</dd>
<dt><code>?</code></dt>
<dd>declares as optional the preceding character. e.g., <code>monzas?</code> will match monza or monzas, while <code>mon(za)?</code> will match either mon or monza. i.e., <code>x?</code> matches zero or one of <code>x</code>.</dd>
<dt><code>!</code></dt>
<dd>declares negation. e.g., “<code>!string</code>” matches everything except “<code>string</code>”.</dd>
<dt><code>.</code></dt>
<dd>a dot (or period) indicates any single arbitrary character.</dd>
<dt><code>-</code></dt>
<dd>instructs “not to” rewrite the URL, as in “<code>...domain.com.* - [F]</code>”.</dd>
<dt><code>+</code></dt>
<dd>matches one or more of the preceding character. e.g., <code>G+</code> matches one or more G’s, while &#8220;+&#8221; will match one or more characters of any kind.</dd>
<dt><code>*</code></dt>
<dd>matches zero or more of the preceding character. e.g., use “<code>.*</code>” as a wildcard.</dd>
<dt><code>|</code></dt>
<dd>declares a logical “or” operator. for example, <code>(x|y)</code> matches <code>x</code> or <code>y</code>.</dd>
<dt><code>\</code></dt>
<dd>escapes special characters ( <code>^ $ ! . * |</code> ). e.g., use “<code>\.</code>” to indicate/escape a literal dot.</dd>
<dt><code>\.</code></dt>
<dd>indicates a literal dot (escaped).</dd>
<dt><code>/*</code></dt>
<dd>zero or more slashes.</dd>
<dt><code>.*</code></dt>
<dd>zero or more arbitrary characters.</dd>
<dt><code>^$</code></dt>
<dd>defines an empty string.</dd>
<dt><code>^.*$</code></dt>
<dd>the standard pattern for matching everything.</dd>
<dt><code>[^/.]</code></dt>
<dd>defines one character that is neither a slash nor a dot.</dd>
<dt><code>[^/.]+</code></dt>
<dd>defines any number of characters which contains neither slash nor dot.</dd>
<dt><code>http://</code></dt>
<dd>this is a literal statement — in this case, the literal character string, “http://”.</dd>
<dt><code>^domain.*</code></dt>
<dd>defines a string that begins with the term “<code>domain</code>”, which then may be proceeded by any number of any characters.</dd>
<dt><code>^domain\.com$</code></dt>
<dd>defines the exact string “<code>domain.com</code>”.</dd>
<dt><code>-d</code></dt>
<dd>tests if string is an existing directory</dd>
<dt><code>-f</code></dt>
<dd>tests if string is an existing file</dd>
<dt><code>-s</code></dt>
<dd>tests if file in test string has a non-zero value</dd>
</dl>
<p><strong id="gen6">Redirection Header Codes</strong> <small>[ <a href="#top">^</a> ]</small></p>
<ul>
<li>301 &#8211; Moved Permanently</li>
<li>302 &#8211; Moved Temporarily</li>
<li>403 &#8211; Forbidden</li>
<li>404 &#8211; Not Found</li>
<li>410 &#8211; Gone</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.otakbali.com/htaccess-tricks-1-definition.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>write less do more</title>
		<link>http://www.otakbali.com/write-less-do-more.html</link>
		<comments>http://www.otakbali.com/write-less-do-more.html#comments</comments>
		<pubDate>Tue, 27 Oct 2009 12:10:15 +0000</pubDate>
		<dc:creator>andi</dc:creator>
				<category><![CDATA[Tips n Trik]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[batch]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://otakbali.com/?p=43</guid>
		<description><![CDATA[How to save the resource in our project code? Should we repeat writing the same code in every page/file? We can save a lot of our time and resource by putting the same code or lines into a function or procedure. In some programming language, such as Pascal, Batch, C, PHP, etc., we can make [...]]]></description>
			<content:encoded><![CDATA[<div class="wp-caption alignleft" style="width: 267px"><a href="http://i720.photobucket.com/albums/ww207/andiim3/php.png"><img title="php" src="http://i720.photobucket.com/albums/ww207/andiim3/php.png" alt="PHP" width="257" height="167" /></a><p class="wp-caption-text">PHP</p></div>
<p>How to save the resource in our project code? Should we repeat writing the same code in every page/file? We can save a lot of our time and resource by putting the same code or lines into a function or procedure.</p>
<p>In some programming language, such as Pascal, Batch, C, PHP, etc., we can make a single special file where we can store our functions and procedure, also some constant.<span id="more-43"></span></p>
<p>Files which stored functions and procedures generally called &#8220;<strong>library</strong>&#8220;. The reason? coz it store many functions&#8230; I don&#8217;t know the other reasons.. <img src='http://www.otakbali.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>For some constant (variables that store fixed value), we can put it on a editable file, like &#8220;config.php&#8221; in PHP or &#8220;config.tpu&#8221; in Pascal. So if we need some constant, we only need to call that file.</p>
<p>For example, we have some web pages that require same coding and data, but in different web design, should we write the same codes in every page? and how if there&#8217;s a minor change in the codes? it will make us work on those page again.</p>
<p>We can solve that problem by creating a single file that contain the function, and call the function from every page. So, if there&#8217;s any change on the code, we have to modify the file that contain the function only. In PHP, you can also include the file with &#8220;include()&#8221; function rather than calling for the function.</p>
<p>There a lot of free library out there, so you can use them to decrease your time in coding. For example <strong><a href="http://docs.jquery.com/Downloading_jQuery">jQuery</a></strong>, it is a free javascript library that store many function. There&#8217;s also <strong><a href="http://mootools.net">Mootools</a></strong>, it&#8217;s has same function with jQuery.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.otakbali.com/write-less-do-more.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
