<?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; php</title>
	<atom:link href="http://www.otakbali.com/tag/php/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: #2 – Essentials</title>
		<link>http://www.otakbali.com/htaccess-tricks-2-essentials.html</link>
		<comments>http://www.otakbali.com/htaccess-tricks-2-essentials.html#comments</comments>
		<pubDate>Fri, 30 Oct 2009 17:32:08 +0000</pubDate>
		<dc:creator>andi</dc:creator>
				<category><![CDATA[.htaccess]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://otakbali.com/?p=52</guid>
		<description><![CDATA[Commenting your htaccess Files It is an excellent idea to consistenly and logically comment your htaccess files. Any line in an htaccess file that begins with the pound sign ( # ) tells the server to ignore it. Multiple lines require multiple pounds and use letters/numbers/dash/underscore only: # this is a comment # each line [...]]]></description>
			<content:encoded><![CDATA[<p><strong id="ess1">Commenting your htaccess Files</strong> <a name="top"></a></p>
<p>It is an excellent idea to consistenly and logically comment your htaccess files. Any line in an htaccess file that begins with the pound sign ( # ) tells the server to ignore it. Multiple lines require multiple pounds and use letters/numbers/dash/underscore only:</p>
<p><code># this is a comment</code><br />
<code># each line must have its own pound sign</code><br />
<code># use only alphanumeric characters along with dashes - and underscores _</code></p>
<p><span id="more-52"></span></p>
<p><strong id="ess2">Enable Basic Rewriting</strong> <small>[ <a href="#top">^</a> ]</small></p>
<p>Certain servers may not have “<code>mod_rewrite</code>” enabled by default. To ensure <code>mod_rewrite</code> (basic rewriting) is enabled throughout your site, add the following line once to your site’s root htaccess file:</p>
<p><code># enable basic rewriting</code><br />
<code>RewriteEngine on</code></p>
<p><strong id="ess3">Enable Symbolic Links</strong> <small>[ <a href="#top">^</a> ]</small></p>
<p>Enable symbolic links (symlinks) by adding the following directive to the target directory’s htaccess file. Note: for the <code>FollowSymLinks</code> directive to function, <code>AllowOverride Options</code> privileges must be enabled from within the server configuration file :</p>
<p><code># enable symbolic links</code><br />
<code>Options +FollowSymLinks</code></p>
<p><strong id="ess4">Enable AllowOverride</strong> <small>[ <a href="#top">^</a> ]</small></p>
<p>For directives that require <code>AllowOverride</code> in order to function, such as <code>FollowSymLinks</code> (see above paragraph), the following directive must be added to the server configuration file. For performance considerations, it is important to only enable <code>AllowOverride</code> in the specific directory or directories in which it is required. In the following code chunk, we are enabling the <code>AllowOverride</code> privs only in the specified directory (/www/replace/this/with/actual/directory). Refer to this code for <code>AllowOverride</code> sample:</p>
<p><code># enable allowoverride privileges</code><br />
<code>&lt;Directory /www/replace/this/with/actual/directory&gt;</code><br />
<code>AllowOverride Options</code><br />
<code>&lt;/Directory&gt;</code></p>
<p><strong id="ess5">Rename the htaccess File</strong> <small>[ <a href="#top">^</a> ]</small></p>
<p>Not every system enjoys the extension-only format of htaccess files. Fortunately, you can rename them to whatever you wish, granted the name is valid on your system. Note: This directive must be placed in the server-wide configuration file or it will not work:</p>
<p><code># rename htaccess files</code><br />
<code>AccessFileName ht.access</code></p>
<p>Note: If you rename your htaccess files, remember to update any associated configuration settings. For example, if you are protecting your htaccess file via <code>FilesMatch</code>, remember to inform it of the renamed files:</p>
<p><code># protect renamed htaccess files</code><br />
<code>&lt;FilesMatch "^ht\."&gt;</code><br />
<code>Order deny,allow</code><br />
<code>Deny from all</code><br />
<code>&lt;/FilesMatch&gt;</code></p>
<p><strong id="ess6">Retain Rules Defined in httpd.conf</strong> <small>[ <a href="#top">^</a> ]</small></p>
<p>Save yourself time and effort by defining replicate rules for multiple virtual hosts once and only once via your httpd.conf file. Then, simply instruct your target htaccess file(s) to inheret the httpd.conf rules by including this directive:</p>
<p><code>RewriteOptions Inherit</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.otakbali.com/htaccess-tricks-2-essentials.html/feed</wfw:commentRss>
		<slash:comments>1</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>
