<?xml version='1.0' encoding='UTF-8'?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-4505192626920795935</atom:id><lastBuildDate>Wed, 15 Apr 2026 19:35:26 +0000</lastBuildDate><category>php</category><category>CodeIgniter</category><category>Bootstrap</category><category>jQuery</category><category>MySQL</category><category>html</category><category>css</category><category>json</category><category>Bootstrap Customization</category><category>CodeIgniter Database Tutorials</category><category>AJAX</category><category>CodeIgniter Bootstrap</category><category>API</category><category>CodeIgniter Query</category><category>JavaScript</category><category>jQuery Plugin</category><category>Reviews</category><category>File Upload</category><category>Navbar</category><category>CodeIgniter Basics</category><category>Bootstrap Basics</category><category>Conversions</category><category>Google API</category><category>Arrays</category><category>Bootstrap Forms</category><category>CSS Buttons</category><category>CSV</category><category>CodeIgniter Tutorials</category><category>Contact Form</category><category>Font Awesome</category><category>HTML5</category><category>Image Effects</category><category>PDF</category><category>SMTP</category><category>Social Media Icons</category><category>Autocomplete Textbox</category><category>Bootstrap Buttons</category><category>Database Joins</category><category>Google Maps API</category><category>HTML Form</category><category>Laptops</category><category>Pagination</category><category>Programming</category><category>Send Email</category><category>XML</category><category>codeigniter Forms</category><category>jQuery UI</category><category>Apache</category><category>Bootstrap Custom CSS</category><category>Bootstrap Jumbotron</category><category>Bootstrap Table</category><category>CRUD</category><category>CSV to MySQL</category><category>CURL</category><category>CodeIgniter File Upload</category><category>Composer</category><category>DomPDF</category><category>Image Gallery</category><category>Insert JSON to MySQL in PHP</category><category>JSON to MySQL</category><category>Laravel</category><category>Login Form</category><category>Menus</category><category>PHP Insert JSON into MySQL</category><category>Popover</category><category>Registration Form</category><category>Scraper</category><category>Select2</category><category>Treeview</category><category>Wireless Adapters</category><category>XAMPP</category><category>email</category><category>htaccess</category><category>Best List</category><category>BlueHost</category><category>Bootstrap CSS Classes</category><category>Bootstrap Carousel</category><category>Bootstrap Example</category><category>Bootstrap Images</category><category>Bootstrap Modals</category><category>CI Version</category><category>CMS</category><category>CSS Property</category><category>CSV to JSON</category><category>Captcha</category><category>Charts</category><category>CodeIgniter Bootstrap Login</category><category>CodeIgniter Delete Database</category><category>CodeIgniter Sessions</category><category>CodeIgniter Update Database</category><category>DOM Parser</category><category>Datatables</category><category>Delete in CodeIgniter</category><category>Desktops</category><category>Dropdown</category><category>FTP</category><category>File Download</category><category>File Operations</category><category>Glyphicons</category><category>Gmail</category><category>Google Charts</category><category>IP Address</category><category>Image Manipulation</category><category>Infographics</category><category>Insert in CodeIgniter</category><category>JSON to CSV</category><category>Kali Linux</category><category>Keyboards</category><category>Laravel 5.6</category><category>Lightbox Effect</category><category>Login</category><category>Mobiles</category><category>Modal Form</category><category>Monitors</category><category>Multidimensional Arrays</category><category>MySQL to CSV</category><category>MySQL to JSON</category><category>MySQLi</category><category>PDO</category><category>PHP Hosting</category><category>PHPMailer</category><category>Payment Gateway</category><category>Programming Laptops</category><category>Registration</category><category>Rewrite URL</category><category>Security</category><category>Software</category><category>Tables</category><category>Text Effects</category><category>USB Dongles</category><category>Ultrabooks</category><category>Update in CodeIgniter</category><category>Validation</category><category>Web Crawler</category><category>Web Hosting</category><category>Writing Laptops</category><category>YouTube API</category><category>bootstrap Search</category><category>menu bar</category><title>KodingMadeSimple</title><description>Koding Made Simple is a Programming Blog focussed on providing quality web design and web development tutorials on PHP, CodeIgniter, Bootstrap, jQuery and MySQL, HTML5, CSS3 Tutorials, Demos and Code Snippets.</description><link>http://www.kodingmadesimple.com/</link><managingEditor>noreply@blogger.com (Valli)</managingEditor><generator>Blogger</generator><openSearch:totalResults>246</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-5213912592702466145</guid><pubDate>Tue, 24 Jul 2018 15:33:00 +0000</pubDate><atom:updated>2018-07-24T21:03:41.888+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">email</category><category domain="http://www.blogger.com/atom/ns#">Gmail</category><category domain="http://www.blogger.com/atom/ns#">Laravel</category><category domain="http://www.blogger.com/atom/ns#">Laravel 5.6</category><category domain="http://www.blogger.com/atom/ns#">SMTP</category><title>How to Send Email in Laravel 5.6 using Gmail SMTP</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! Today let&#39;s see &lt;strong&gt;how to send email in laravel 5.6 using gmail smtp server&lt;/strong&gt;. Since Laravel 5.3, the framework comes with the clean, simple API to send mails quickly via localhost or cloud based service. You can simply use the &#39;Mailable&#39; class to build your emails.&lt;/p&gt;

&lt;p&gt;These classes collect the data and pass it to the view. Any property set as public will be available in the view file. So all you have to do is to set the class property as public and access it via the blade template. You can also send customized data explicitly using the &lt;code&gt;with()&lt;/code&gt; method. Please refer the &lt;a href=&quot;https://laravel.com/docs/5.6/mail&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;laravel documentation&lt;/a&gt; for more details.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;send email laravel gmail smtp server&quot; border=&quot;0&quot; data-original-height=&quot;373&quot; data-original-width=&quot;586&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgcHJSxEQFmRteU14Th3No7yym5CFpgpevAjsSoEs0A89uTEWAN40so9m-_zrVgjHZ1_pLa1fXIRDWttmYMn8ZLNgh9oIya2OWJyrKHN7DlTXMTOR4ER2Wtg3_23XvDHUZPmhja4B5zh4Y/s1600/send-email-laravel-gmail-smtp-server.png&quot; title=&quot;Sending Email in Laravel&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;Laravel - Sending Email via Gmail SMTP:&lt;/h2&gt;

&lt;p&gt;Laravel utilizes the &lt;strong&gt;&#39;config\mail.php&#39;&lt;/strong&gt; file to store all the mail settings.  Here is where you have to configure MAIL_DRIVER, MAIL_HOST, MAIL_PORT, etc.&lt;/p&gt;

&lt;p&gt;But you don&#39;t have to directly make changes to this file. You can simply provide those details on the &#39;.env&#39; file found in the app root and laravel will automatically find the required settings.&lt;/p&gt;

&lt;p&gt;Here go the steps to send mail using gmail smtp server in laravel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-1)&lt;/strong&gt; First install the latest version of laravel which is 5.6 as of now. Open up the terminal and fire the below composer command to install it.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
composer create-project laravel/laravel laravel_demo --prefer-dist
&lt;/pre&gt;

&lt;p&gt;Here &#39;laravel_demo&#39; is your project folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-2)&lt;/strong&gt; Next open up the &lt;strong&gt;&#39;.env&#39;&lt;/strong&gt; file and configure the email settings. I&#39;m going to use gmail server for sending the email. So we must provide the gmail smtp details here.&lt;/p&gt;

&lt;h3&gt;Gmail SMTP Settings:&lt;/h3&gt;

&lt;blockquote&gt;&lt;pre&gt;
Host Name: smtp.gmail.com
Smtp Port: 587(tls), 465(ssl)
Encryption: tls/ssl&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;Your &#39;.env&#39; file should look like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=your_gmail_id
MAIL_PASSWORD=your_gmail_password
MAIL_ENCRYPTION=ssl
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-3)&lt;/strong&gt; Then generate the mailable class. Fire up the below command on the command prompt.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
php artisan make:mail WelcomeUser
&lt;/pre&gt;

&lt;p&gt;This will create &lt;strong&gt;&#39;WelcomeUser.php&#39;&lt;/strong&gt; file inside &lt;strong&gt;&#39;App\Mail&#39;&lt;/strong&gt; folder. We have created this to send welcome email to user. This class is going to contain only one property which is &#39;uname&#39;. This member variable represents the user&#39;s name which will be passed from the controller.&lt;/p&gt;

&lt;h5&gt;WelcomeUser.php&lt;/h5&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;

class WelcomeUser extends Mailable
{
    use Queueable, SerializesModels;
 
    public $uname;

    /**
     * Create a new message instance.
     *
     * @return void
     */
    public function __construct($uname)
    {
        $this-&amp;gt;uname = $uname;
    }

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        return $this-&amp;gt;view(&#39;email.welcome&#39;);
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-4)&lt;/strong&gt; Next create the view file. This will contain the template for our email. Create &lt;strong&gt;&#39;email&#39;&lt;/strong&gt; folder inside &lt;strong&gt;&#39;views&#39;&lt;/strong&gt; and place &lt;strong&gt;&#39;welcome.blade.php&#39;&lt;/strong&gt; file inside it.&lt;/p&gt;

&lt;h5&gt;welcome.blade.php&lt;/h5&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;Welcome User&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
 &amp;lt;div&amp;gt;
  &amp;lt;h2&amp;gt;Hi {{ $uname }}! Welcome to KodingMadeSimple.com&amp;lt;h2&amp;gt;
 &amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Above we have a very simple template that displays welcome message to the user.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-5)&lt;/strong&gt; Next generate a controller file with the below artisan command.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
php artisan make:controller UserController
&lt;/pre&gt;

&lt;p&gt;Open the &lt;strong&gt;&#39;UserController.php&#39;&lt;/strong&gt; file inside &lt;strong&gt;&#39;App\Http\Controllers&#39;&lt;/strong&gt; folder and add &lt;code&gt;send_mail()&lt;/code&gt; function to it. Also make sure to include the path for Mail Facade and WelcomeUser class.&lt;/p&gt;

&lt;h5&gt;UserController.php&lt;/h5&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
...

use Illuminate\Support\Facades\Mail;
use App\Mail\WelcomeUser;

...

public function send_email()
{
 $user_name = &#39;John Anderson&#39;;
 $to = &#39;john.anderson@gmail.com&#39;
 Mail::to($to)-&amp;gt;send(new WelcomeUser($user_name));
 return &#39;Mail sent successfully&#39;;
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step-6)&lt;/strong&gt; Finally add route for our UserController&#39;s &lt;code&gt;send_mail()&lt;/code&gt; function. Open &#39;routes\web.php&#39; file and add the below route to it.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
Route::get(&#39;/user/sendmail&#39;, &#39;HomeController@send_email&#39;);
&lt;/pre&gt;

&lt;p&gt;Done! Now start the artisan server.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
php artisan serve
&lt;/pre&gt;

&lt;p&gt;Open the browser and enter the url &lt;code&gt;http://localhost:8000/user/sendmail&lt;/code&gt; and if everything went right you&#39;ll see the below screen.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;laravel send email using mailable&quot; border=&quot;0&quot; data-original-height=&quot;306&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgR_TyrObHKF91OS0gozGZl94gXwYSvF_JFIWT5o8RN0H-VhXEIr0vhuuFRfF7UHHiFybzFPPB0IegnTmMYxXZblujrR_G38Yh1viWUCq_sPVoOy3rKubJWsDMx1d4_y9dg9kCXmxWDFHRE/s1600/laravel-send-email-using-mailable.png&quot; title=&quot;Laravel Mailable Example&quot; /&gt;&lt;/div&gt;

&lt;p&gt;If you don&#39;t receive the email, don&#39;t worry. Do the following changes to your gmail settings.&lt;/p&gt;

&lt;h3&gt;Gmail Settings:&lt;/h3&gt;

&lt;p&gt;Login to your Google account and go to &lt;strong&gt;&#39;My Account&#39;&lt;/strong&gt; &amp;gt; &lt;strong&gt;&#39;Sign-in &amp; Security&#39;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Scroll down to the bottom and look for &lt;strong&gt;&#39;Allow less secure apps&#39;&lt;/strong&gt; option. If it is set &lt;strong&gt;&#39;OFF&#39;&lt;/strong&gt;, then turn it &lt;strong&gt;&#39;ON&#39;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Now try it again and you&#39;ll receive the mail without any issues.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2018/06/install-laravel-windows-composer.html&quot;&gt;How to Install Laravel 5.6 on Windows using Composer&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can even queue the emails. Just call the &lt;code&gt;queue()&lt;/code&gt; method instead of &lt;code&gt;send()&lt;/code&gt; with &lt;strong&gt;Mail::to&lt;/strong&gt;. Likewise you can send emails in laravel via gmail smtp. I hope you find this post useful. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/07/send-email-laravel-gmail-smtp.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhgcHJSxEQFmRteU14Th3No7yym5CFpgpevAjsSoEs0A89uTEWAN40so9m-_zrVgjHZ1_pLa1fXIRDWttmYMn8ZLNgh9oIya2OWJyrKHN7DlTXMTOR4ER2Wtg3_23XvDHUZPmhja4B5zh4Y/s72-c/send-email-laravel-gmail-smtp-server.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-8961992709309914516</guid><pubDate>Tue, 19 Jun 2018 08:49:00 +0000</pubDate><atom:updated>2018-06-19T14:19:32.678+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Composer</category><category domain="http://www.blogger.com/atom/ns#">Laravel</category><category domain="http://www.blogger.com/atom/ns#">php</category><title>How to Install Laravel 5.6 on Windows using Composer</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Here let&#39;s see &lt;strong&gt;how to install laravel on windows using composer&lt;/strong&gt;. Ever since its launch, laravel has become the most popular php framework and not without a good reason. It&#39;s a great alternative to CodeIgniter which is another popular MVC for php. Laravel ships with so many goodies out of the box than other frameworks do.&lt;/p&gt;

&lt;p&gt;Mastering laravel will definitely take some time, but the time spent is well worth it in the long run. And it will save loads of time in application development. Anyhow, here you are, planned to move on to laravel and want to install it for the first time. Without wasting the time, let&#39;s dive into the process of installing laravel on windows machine.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;step by step install laravel on windows composer&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvIqyZqgIy8uJKdqfw2QVsmEJWxKlYd_eMupWfpPIgxz9hhHEXh8yd0IIv0-ZdzrW4rxPIVwz1rPE4GII-SnBJ2GyL_3A0QncOGa6oRBz65OmfB9TLMmwMaLuAzCVGidQQwwPJ-giMxU4K/s1600/step-by-step-install-laravel-on-windows-composer.png&quot; title=&quot;Laravel Installation on Windows&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;System Requirements for Laravel:&lt;/h2&gt;

&lt;p&gt;As of now, the latest laravel version is 5.6. And you have to make sure the below system requirements is met to install and use it on your machine.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
 &lt;li&gt;PHP &amp;gt;= 7.1.3&lt;/li&gt;
 &lt;li&gt;OpenSSL PHP Extension&lt;/li&gt;
 &lt;li&gt;PDO PHP Extension&lt;/li&gt;
 &lt;li&gt;JSON PHP Extension&lt;/li&gt;
 &lt;li&gt;XML PHP Extension&lt;/li&gt;
 &lt;li&gt;Ctype PHP Extension&lt;/li&gt;
 &lt;li&gt;Mbstring PHP Extension&lt;/li&gt;
 &lt;li&gt;Tokenizer PHP Extension&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;Reference: &lt;a href=&quot;https://laravel.com/docs/5.6/installation#server-requirements&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;Laravel website&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Prerequisite: Composer&lt;/h2&gt;

&lt;p&gt;Laravel requires Composer to manage the project dependencies. So before installing Laravel, make sure you have Composer installed on your system. In case you are hearing about Composer for the first time, it&#39;s a dependency management tool for php similar to node&#39;s npm.&lt;/p&gt;

&lt;p&gt;To install Composer on your machine, check this post:&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2018/05/install-composer-windows-xampp.html&quot;&gt;How to install Composer on Windows using XAMPP&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;Installing Laravel on Windows:&lt;/h2&gt;

&lt;p&gt;Follow the below steps to install laravel on windows machine. No matter you have xampp/wamp stack, it works for both. On WAMP, make sure to install laravel on &#39;www&#39; folder and on XAMPP, obviously the &#39;htdocs&#39;.&lt;/p&gt;

&lt;p&gt;STEP-1) Open &#39;htdocs&#39; folder on XAMPP, hold &lt;code&gt;SHIFT&lt;/code&gt; key and right click on the folder, and choose &#39;open command window here&#39;. Alternatively, you can open command window and change directory to &#39;xampp/htdocs&#39;.&lt;/p&gt;

&lt;p&gt;STEP-2) Enter the following command.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
composer create-project laravel/laravel my_laravel_site --prefer-dist
&lt;/pre&gt;

&lt;p&gt;Here &#39;my_laravel_site&#39; is the folder name where laravel files will be installed. Change this to your liking.&lt;/p&gt;

&lt;p&gt;STEP-3) Now it&#39;s time to be patient as laravel installation is going to take some time.&lt;/p&gt;

&lt;p&gt;STEP-4) Once installed, change directory to &#39;my_laravel_site&#39; (cd &#39;my_laravel_site&#39;) on the command prompt and enter the below command.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
php artisan serve
&lt;/pre&gt;

&lt;p&gt;STEP-5) This will show a message something like, &#39;Laravel development server started:&#39; along with an url.&lt;/p&gt;

&lt;p&gt;STEP-6) Copy and paste the url on the browser. If things go right, you&#39;d see the laravel welcome screen.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;laravel welcome screen&quot; border=&quot;0&quot; data-original-height=&quot;355&quot; data-original-width=&quot;580&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkOO_PqcNT0CNAynCeyV9tMu1jGtTJ9hkQAx3fXiE2sU_NJLHhAwjXoghBBZaSaaAYvWu_6fZm6KjTpsXgPcpwirkzVdEMUJ9dMbuT4Pzik6GqWjsE0T7FQMEyX_WpThz0rcknvyVZHxK9/s1600/laravel-welcome-screen.jpg&quot; title=&quot;Laravel Home Page&quot; /&gt;&lt;/div&gt;

&lt;p&gt;STEP-7) Done! You have successfully installed laravel on windows machine and ready to go with.&lt;/p&gt;

&lt;h3&gt;Setting Application Key:&lt;/h3&gt;

&lt;p&gt;Laravel requires little configuration after installation. It requires you to set the application key. This is a random string of 32 characters long used for encrypting session and other sensitive data. Usually this will be set automatically when you install laravel via composer or laravel installer.&lt;/p&gt;

&lt;p&gt;In case it&#39;s not set, you have to do it manually. First make sure to rename the &#39;.env.example&#39; file to &#39;.env&#39; on your application root. Then open command prompt and change to the laravel project folder. Now run the below command to generate the key.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
php artisan key:generate
&lt;/pre&gt;

&lt;p&gt;Copy this generated key to the &lt;code&gt;APP_KEY&lt;/code&gt; variable on &#39;.env&#39; file. Save and you are done.&lt;/p&gt;

&lt;h3&gt;Installing Specific Laravel Version:&lt;/h3&gt;

&lt;p&gt;The above given method will make composer to download and install the latest version of laravel. If you want to install earlier versions of laravel on your machine, make sure to include the respective version number on &lt;code&gt;create-project&lt;/code&gt; command.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
composer create-project laravel/laravel=5.4 your-project-name --prefer-dist
&lt;/pre&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2018/06/secure-passwords-php.html&quot;&gt;How to Secure Passwords in PHP and Store in Database&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2018/05/change-apache-mysql-port-number-xampp.html&quot;&gt;How to Change Apache and MySQL Port Number in XAMPP&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Likewise you can &lt;em&gt;easily install laravel using composer on windows&lt;/em&gt;. I hope you find this tutorial useful. Please share it on your social circle if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/06/install-laravel-windows-composer.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvIqyZqgIy8uJKdqfw2QVsmEJWxKlYd_eMupWfpPIgxz9hhHEXh8yd0IIv0-ZdzrW4rxPIVwz1rPE4GII-SnBJ2GyL_3A0QncOGa6oRBz65OmfB9TLMmwMaLuAzCVGidQQwwPJ-giMxU4K/s72-c/step-by-step-install-laravel-on-windows-composer.png" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-7191491197651648601</guid><pubDate>Fri, 08 Jun 2018 13:52:00 +0000</pubDate><atom:updated>2018-06-08T19:22:50.679+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CSV</category><category domain="http://www.blogger.com/atom/ns#">File Operations</category><category domain="http://www.blogger.com/atom/ns#">php</category><title>How to Create and Download CSV File in PHP</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! Here we will see &lt;strong&gt;how to create a csv file and download it using php&lt;/strong&gt;. CSV is one of the popular data storage methods used on the Web. Being a modern language, PHP has no problems handling various data formats including csv. It offers native functions to read and write csv files. With &lt;code&gt;fputcsv()&lt;/code&gt; method, you can write data as a csv file and force it to download.&lt;/p&gt;

&lt;p&gt;Clicking on a file url (link) will just open it in the browser window without downloading. The exe and zip formats are an exception here. But in case you need to download it directly to client&#39;s hard disk, then you have to make use of the &lt;code&gt;readfile()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Let&#39;s see how to do it.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;php create download csv file&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6vwLk1rgAIptV_7SdA53DRJXg6GELlQmsRUy5FZi31BsHRPvD80LQkOUpmznqzdevPU_899zXNSSM3Xhu7bzZZDhJO9qONmgmw4iaMbN-CyoSXTleV0VrTxlIA77BrMcPCqdkWx0wYzII/s1600/php-create-download-csv-file.png&quot; title=&quot;Create and Download CSV File&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;PHP - Create CSV File:&lt;/h2&gt;

&lt;p&gt;The following snippet creates a csv file named &#39;myfile.csv&#39; on your current working directory.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
// data array
$user = array(1, &#39;Johnson&#39;, &#39;johnson@mydomain.com&#39;, &#39;Miami&#39;);
// filename
$filename = &#39;myfile.csv&#39;;

// write to csv file
$fp = fopen($filename, &#39;w&#39;);
fputcsv($fp, $user);
fclose($fp);
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Okay! We have created the csv file. Next we&#39;ll move on to the download part.&lt;/p&gt;

&lt;h2&gt;Download CSV File:&lt;/h2&gt;

&lt;p&gt;As I said before, you must use readfile() along with the proper header to force download of the file. Here&#39;s the code to do it,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
// download file
header(&#39;Content-type: text/csv&#39;);
header(&#39;Content-disposition:attachment; filename=&quot;&#39;.$filename.&#39;&quot;&#39;);
readfile($filename);
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Sending the header along with the download option will force open the &#39;Save File&#39; dialog in the user&#39;s browser window.&lt;/p&gt;

&lt;p&gt;We have used two &lt;code&gt;header()&lt;/code&gt; functions in the above script.&lt;/p&gt;

&lt;p&gt;The first one sets the MIME type of the content sent. Since it is &#39;text/csv&#39; for csv data, we need to set it as the &#39;Content-type&#39;.&lt;/p&gt;

&lt;p&gt;The second line provides the filename to be used for storing and force the browser to display the save dialog.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2016/05/how-to-write-json-to-file-in-php.html&quot;&gt;How to Write JSON Data to File using PHP&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2018/02/php-download-file-from-url-curl.html&quot;&gt;Download Remote File from URL using PHP CURL&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That explains &lt;em&gt;how to create csv file and automatically download it in php&lt;/em&gt;. I hope you find this post useful. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/06/create-download-csv-file-php.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj6vwLk1rgAIptV_7SdA53DRJXg6GELlQmsRUy5FZi31BsHRPvD80LQkOUpmznqzdevPU_899zXNSSM3Xhu7bzZZDhJO9qONmgmw4iaMbN-CyoSXTleV0VrTxlIA77BrMcPCqdkWx0wYzII/s72-c/php-create-download-csv-file.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-2171526046532853911</guid><pubDate>Sun, 03 Jun 2018 17:37:00 +0000</pubDate><atom:updated>2018-06-03T23:07:10.132+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>How to use PHP PREG MATCH function to validate Form Input</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;In this post we&#39;ll see how to do some basic &lt;strong&gt;PHP validations &lt;/strong&gt; of form input using &lt;strong&gt;preg_match()&lt;/strong&gt; function.  One of the &lt;strong&gt;vulnerable spot &lt;/strong&gt; in a website which attracts malicious hackers are the &lt;strong&gt;user input forms&lt;/strong&gt; like registration form, contact form etc.  Validating the user input before processing is the first and foremost step in &lt;strong&gt;securing&lt;/strong&gt; the site.  The validation includes checking if the data we received is in the right format and length.  Generally it&#39;s a practice among web developers to do validation check at the client side (like java script).  Still it’s easy for someone to break thru it and harm your site.  So it&#39;s strictly advisable to do these &lt;strong&gt;validations on the server side (like PHP)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Generally we receive the form input as string and we can use preg_match with appropriate &lt;strong&gt;regular expression&lt;/strong&gt; to check a required pattern in the input string.&lt;/p&gt;

&lt;h2&gt;Preg Match Syntax&lt;/h2&gt;

&lt;p&gt;Before dwelling into the validation process, here take a sneak peak at the syntax of preg match function.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;PHP Preg Match Syntax&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggwadryv3qdfTbXI_x_98RvF55YiV7EGYxFolWodA2_My27DgrZnl_10WGFl_-C94_TCXnQfYNZaRGSas14RK4zhfNjnm-y7soNGh_A2Ayik7vqqSbAMUjWsAtNvWcCkgD7vy6GIzH86fT/s1600/php+preg+match+syntax.png&quot; title=&quot;PHP Preg Match Syntax&quot; width=&quot;500&quot; /&gt;&lt;/div&gt;

&lt;h3&gt;1. Form Input should contain only alphabets &lt;/h3&gt;

&lt;p&gt;Say we have a &quot;Name&quot; field in which we want the user to enter only alphabets.  Then we can do the checking by this PHP code,&lt;/p&gt;
  
&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$name = $_POST[&quot;Name&quot;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!preg_match(&quot;/^[a-zA-Z]+$/&quot;,$name)) { die (&quot;Invalid Name&quot;);}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Where in the regular expression, ^ matches the start of the string and $ matches the end of the string.  Also &quot;a-zA-Z&quot; is used in the expression to include both upper and lower case alphabets.&lt;/p&gt;
&lt;p&gt;The above code checks each character of the string against the regular expression and throws error incase if there is any other character other than alphabet present in the string.&lt;/p&gt;
 
&lt;h3&gt;2.  Form Input should contain only alphanumeric characters&lt;/h3&gt;

&lt;p&gt;In case we want a field (eg., &quot;username&quot;) to contain only alphanumeric characters then we can alter the above preg_match expression to include 0-9 numbers too.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt; 
&amp;lt;?php
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$username = $_POST[&quot;Username&quot;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!preg_match(&quot;/^[a-zA-Z0-9]+$/&quot;,$username)) { die (&quot;Invalid Username&quot;);}
?&amp;gt;
&lt;/pre&gt;
 
&lt;h3&gt;3. First character should be alphabet&lt;/h3&gt;

&lt;p&gt;We can also force a field&#39;s first character to be an alphabet.  Let’s take the same &quot;username&quot; example.  It can contain alphanumeric characters but we want the first character to be an alphabet.  The below code will check if the first character is an alphabet.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$username = $_POST[&quot;Username&quot;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!preg_match(&quot;/^[a-zA-Z]/&quot;,$Username)) { die (&quot;Username should start with an alphabet&quot;);}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Instead of using the expression &quot;/^[a-zA-Z]/&quot;, we can use &quot;/^[a-z]/i&quot; also.  Here ‘i’ represents case independent ie., includes both uppercase and lowercase alphabets.&lt;/p&gt;

&lt;h3&gt;4. Form Input should contain alphanumeric with special characters&lt;/h3&gt;

&lt;p&gt;What if you want the input field to contain special characters also? Here is an expression that let the string to have alphanumeric characters along with hyphen (-) and space.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!preg_match(&quot;/^[a-zA-Z\-\ ]+$/&quot;,$name)) { die (&quot;Invalid Name&quot;);}
?&amp;gt;
&lt;/pre&gt;
 
&lt;h3&gt;5. Check for valid Email-ID&lt;/h3&gt;

&lt;p&gt;The below code will check if the given email id is a valid one.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt; 
&amp;lt;?php
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$emailid = $_POST[&quot;Emailid&quot;];
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if(!preg_match(&quot;/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/&quot;,$emailid)) { die (&quot;Invalid Email-ID&quot;);}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;We have discussed so far some of the common validations we should employ while validating a form.  Though it will take a while to warm up with regular expressions, they are quite powerful and using the right expression will do the trick.&lt;/p&gt;

&lt;p&gt;Hope you would have enjoyed this article.  If you find this one useful, please share it in your circle.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2014/04/use-php-preg-match-function-for-form-validation.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggwadryv3qdfTbXI_x_98RvF55YiV7EGYxFolWodA2_My27DgrZnl_10WGFl_-C94_TCXnQfYNZaRGSas14RK4zhfNjnm-y7soNGh_A2Ayik7vqqSbAMUjWsAtNvWcCkgD7vy6GIzH86fT/s72-c/php+preg+match+syntax.png" height="72" width="72"/><thr:total>3</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-6239054399494012635</guid><pubDate>Fri, 01 Jun 2018 15:14:00 +0000</pubDate><atom:updated>2018-06-01T20:44:53.977+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">Security</category><title>How to Secure Passwords in PHP and Store in Database</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! Here let&#39;s see &lt;strong&gt;how to secure passwords in php&lt;/strong&gt;. Developers have a huge responsibility when handling sensitive user data, such as password. They must take necessary precautions to store the password and other sensitive information in a secure manner. Old-school methods use the md5 algorithm to hash passwords and store them in the database. This really is not safe and vulnerable to attack.&lt;/p&gt;

&lt;p&gt;But thanks to the community, PHP 5.5 and higher comes with the &lt;strong&gt;password_hash&lt;/strong&gt; function that generates one-way hash that is extremely secure to store passwords in the database. Below, we will see how to securely hash passwords, store them in the database and verify them against the user given password in php.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;php secure password and store in database&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUO_vEwW0WmU7XqPAtgdd53x0lKMSb7_m7IZnJMap9eBcumd4ddAPLQMKIz1TCvsahIlFRK0sn1ZermvjHZodIOtagGGkiK7jaM-oBT65cceSM_ad2dq46jJAtedLZMx-vDRJGw62Vu4Qs/s1600/php-secure-password-store-database.jpg&quot; title=&quot;Secure Passwords&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;PHP - Secure Way to Store Passwords:&lt;/h2&gt;

&lt;p&gt;If you are a budding developer, these are some things to keep in mind when handling the password.&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;Never store passwords as plain text. It&#39;s as good as not having a password at all.&lt;/li&gt;
 &lt;li&gt;Never use MD5 or SHA1 for hashing. They are extremely fast and vulnerable to brute force attack. A powerful GPU could easily break the md5 hash.&lt;/li&gt;
 &lt;li&gt;Never try to make your own password hashing. Someone could easily outrun your smartness putting the system vulnerable.&lt;/li&gt;
 &lt;li&gt;Don&#39;t even associate password with encryption, as there is this chance to decrypt which is a big NO. Instead, you must use salted one-way hashing for the password.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, what to use to protect passwords?&lt;/p&gt;

&lt;h4&gt;Use password_hash:&lt;/h4&gt;

&lt;p&gt;With PHP v5.5+, you are lucky to have the built-in &lt;code&gt;password_hash()&lt;/code&gt; function, that uses BCRYPT algorithm to hash the password.&lt;/p&gt;

&lt;p&gt;The good thing about BCRYPT is that it is very slow compared to md5 and sha1. This makes it computationally expensive to brute force. Plus, you can also change the algorithmic cost factor to make it tougher to break.&lt;/p&gt;

&lt;h3&gt;How to Hash Password?&lt;/h3&gt;

&lt;p&gt;To hash the password, pass the password string and the algorithm you want to use for the password_hash.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
$email = mysqli_real_escape_string($_POST[&#39;email&#39;]);
$password = mysqli_real_escape_string($_POST[&#39;password&#39;]);
$hash = password_hash($password, PASSWORD_BCRYPT);
$sql = &quot;insert into users (email, password_hash) values ($email, $hash)&quot;;
mysqli_query($con, $sql);
?&amp;gt;
&lt;/pre&gt;

&lt;blockquote&gt;The password_hash function will automatically generate a random salt that is cryptographically secure. Therefore, it is strongly recommended that you do not provide your own salt (though you can) for the function.&lt;/blockquote&gt;

&lt;h3&gt;What should be the length of the Password field?&lt;/h3&gt;

&lt;p&gt;Be sure to use at least varchar(60) column to store the password hash, since BCRYPT returns 60 characters length string. But you can keep it to up to 255 characters long if you are considerate about future upgrade to accommodate a much stronger algorithm.&lt;/p&gt;

&lt;h3&gt;How to Verify User Password?&lt;/h3&gt;

&lt;p&gt;To verify the password, you must use the function &lt;code&gt;password_verify()&lt;/code&gt; which will check the password given by the user against the hash created by password_hash. It returns true if the password and the hash match and false otherwise.&lt;/p&gt;

&lt;p&gt;Here&#39;s the rough usage of the function,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
$email = mysqli_real_escape_string($_POST[&#39;email&#39;]);
$password = mysqli_real_escape_string($_POST[&#39;password&#39;]);
$sql = &quot;select * from users where email=$email&quot;;
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result) &amp;gt; 0) {
    $user = mysqli_fetch_assoc($result);
    if(password_verify($password, $user[&#39;password&#39;]))
        echo &#39;Valid password!&#39;;
    else
        echo &#39;Invalid password!&#39;;
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;If you are using PHP 5.3.7+, use this &lt;a href=&quot;https://github.com/ircmaxell/password_compat&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;https://github.com/ircmaxell/password_compat&lt;/a&gt; library that helps you to use &lt;code&gt;password_*&lt;/code&gt; functions on older php servers.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2016/01/php-login-and-registration-script-with-mysql-example.html&quot;&gt;User Sign up and Login Form with PHP &amp; MySQL&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2018/05/convert-pdf-to-jpeg-php.html&quot;&gt;How to Convert PDF to JPEG Image using PHP&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Guess now you have a clear idea of &lt;em&gt;storing passwords securely in the database with php&lt;/em&gt;. No matter how awesome your application, it would be nothing without the proper security measures. I hope you find this post useful. Please, share it on your social circle if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/06/secure-passwords-php.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjUO_vEwW0WmU7XqPAtgdd53x0lKMSb7_m7IZnJMap9eBcumd4ddAPLQMKIz1TCvsahIlFRK0sn1ZermvjHZodIOtagGGkiK7jaM-oBT65cceSM_ad2dq46jJAtedLZMx-vDRJGw62Vu4Qs/s72-c/php-secure-password-store-database.jpg" height="72" width="72"/><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-3498646588374699386</guid><pubDate>Sat, 26 May 2018 13:59:00 +0000</pubDate><atom:updated>2018-05-26T19:29:29.048+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Composer</category><category domain="http://www.blogger.com/atom/ns#">XAMPP</category><title>How to Install Composer on Windows with XAMPP</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Now-a-days, many modern php frameworks like laravel, symfony, &lt;a href=&quot;https://www.kodingmadesimple.com/2015/06/php-codeigniter-tutorials-for-beginners-step-by-step.html&quot;&gt;codeigniter&lt;/a&gt; and other libraries use the composer to manage their dependencies. So you need composer to install them on your machine. In case you don&#39;t know, &lt;em&gt;Composer is the tool for dependency management in php&lt;/em&gt;. It allows you to declare the dependency libraries and packages required for a project and it will install, update and manage them for you. Composer will never maintain anything globally by default but rather on per-project basis.&lt;/p&gt;

&lt;p&gt;You need PHP 5.3.2 and above to use Composer. So make sure the system requirements are met before installing it on your machine. In addition, you must also make some changes to the php settings to make it work.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;install composer on windows xampp&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7980OqRwW_KlmuZnXPKrUCKYj9m_SW9QE0TggyHYPWunl7v5RAlMSn_WVLMLGqKyYzBbKMYSQymH7RVbWDpYd4J12SVCgod51cT65l7STndalGOcgisq-bVqQwdYP3otByWmKlkXkuIP2/s1600/install-composer-on-windows-xampp.png&quot; title=&quot;Composer Installation&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;Change Settings on php.ini:&lt;/h2&gt;

&lt;p&gt;I hope you have &lt;strong&gt;XAMPP&lt;/strong&gt; installed already on your machine. So before composer installation, do the following changes on your &lt;strong&gt;php.ini&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Go to &lt;strong&gt;[path-to-xampp]/php&lt;/strong&gt; folder and open &lt;strong&gt;php.ini&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;Locate the below lines one by one and remove the semicolon (;) from the start.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
extension=php_openssl.dll
extension=php_curl.dll
extension=php_sockets.dll
&lt;/pre&gt;

&lt;p&gt;Save the file.&lt;/p&gt;

&lt;h2&gt;Install Composer on Windows:&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;STEP-1)&lt;/strong&gt; First &lt;a href=&quot;https://getcomposer.org/download/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;download composer for windows&lt;/a&gt; and click on the exe file. This will launch the setup for installing composer on your system. Click &#39;Next&#39;.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;install composer step-1&quot; border=&quot;0&quot; data-original-height=&quot;387&quot; data-original-width=&quot;500&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7GNah2qNTdYj1V0iv0Veq4_yxolLJMfTQL1lP9aqEM58M5g5hPuG5_0C4EqaQUYpjlrguihJBGtIXvn3jzbZ4zT03k5IOl_tY2Zc9dix_vSCcVdw1kgeh0O88Ao_uQLmdwf_69a37G6E8/s1600/install-composer-1.png&quot; title=&quot;Install Composer&quot; /&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;STEP-2)&lt;/strong&gt; Next you need to select the path to the php executable file. Just click on the &#39;Browse&#39; button and select &lt;strong&gt;&#39;php.exe&#39;&lt;/strong&gt; file. It can be found inside &lt;strong&gt;[path-to-xampp]/php&lt;/strong&gt; folder. Click &#39;Next&#39;.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;install composer step-2&quot; border=&quot;0&quot; data-original-height=&quot;391&quot; data-original-width=&quot;501&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyGXJMvz1JJ-0TobgQaZA8K2PSQBu_WZ8ievbTpBuA5RatrVdA_t_QqXdVOXJO-VY6Y6Jn30sfAaFD__oV7hbhZZ0AzwH_98poKibZIvg5cDxKkoRXNRFhmbjzuqWkh_aDm7J3WQXY5JCn/s1600/install-composer-2.png&quot; title=&quot;Install Composer&quot; /&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;STEP-3)&lt;/strong&gt; Now a window appears for proxy settings. Just leave it blank for now and click on &#39;Next&#39; button.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;install composer step-3&quot; border=&quot;0&quot; data-original-height=&quot;392&quot; data-original-width=&quot;502&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgO5MdG_GDsmBxwQOsavUm-sfGvqr_H4iuRNWHZp00pAS6Xt5n52SFvOT7CJ5byx-aA_b0QlY2uky8J7lPw_4psMcs-zOMHBY0OsT2OUQ6txRpdp_tfursVm8QTnCRLt6FYG3UL_Jj-0sms/s1600/install-composer-3.png&quot; title=&quot;Install Composer&quot; /&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;STEP-4)&lt;/strong&gt; Finally the ready to install window pops up. Click on &#39;Install&#39; to start installing the tool.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;install composer step-4&quot; border=&quot;0&quot; data-original-height=&quot;391&quot; data-original-width=&quot;500&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9GdEP27LVULjjuUS4UzLstBgORwgkAS0mlNlFvkaQXWgWveECaGj4ZrhPteafe-50gGC0-RwMj88dj8VfhR9uVTMXjPv2hcYU9UY5HlY6O2tMVeLgXU-D2uudU21numXo6KjaCY-AZPZn/s1600/install-composer-4.png&quot; title=&quot;Install Composer&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Done! Once you finished installing composer, you can check it via command line.&lt;/p&gt;

&lt;p&gt;Click on &lt;strong&gt;&#39;Start&#39;&lt;/strong&gt; &amp;gt;&lt;strong&gt; &#39;Run&#39;&lt;/strong&gt; dialogue, type &lt;code&gt;cmd&lt;/code&gt; and click &#39;OK&#39;.&lt;/p&gt;

&lt;p&gt;On the command prompt, simply type &lt;code&gt;composer&lt;/code&gt; and hit enter. If composer is successfully installed on your windows machine, you will see the below screen.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;composer command screen&quot; border=&quot;0&quot; data-original-height=&quot;263&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhBI6V-t0nsCdk7u0k9B1WRBcbaxlcRFTOiZ-4AjGy0SveY1flnhyfFDGm3o_4xUvUMIEprGk8AtbrNfyrQp2Twb35GjgW632zkwV9kkIKldmi1Y42U8GFxhdQYM8O0jMvTjsEi9aePYiYc/s1600/composer-command-5.png&quot; title=&quot;Command Line&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Restart your machine and launch &#39;XAMPP&#39; control panel and start using composer. The same procedure can be used to install composer for &#39;WAMP&#39; stack or even if you have installed php separately.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2018/05/change-apache-mysql-port-number-xampp.html&quot;&gt;How to Change Port Number for Apache and MySQL in XAMPP&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/05/install-composer-windows-xampp.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7980OqRwW_KlmuZnXPKrUCKYj9m_SW9QE0TggyHYPWunl7v5RAlMSn_WVLMLGqKyYzBbKMYSQymH7RVbWDpYd4J12SVCgod51cT65l7STndalGOcgisq-bVqQwdYP3otByWmKlkXkuIP2/s72-c/install-composer-on-windows-xampp.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-8718619256909250889</guid><pubDate>Fri, 18 May 2018 12:45:00 +0000</pubDate><atom:updated>2018-05-18T18:15:08.363+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Apache</category><category domain="http://www.blogger.com/atom/ns#">MySQL</category><category domain="http://www.blogger.com/atom/ns#">XAMPP</category><title>How to Change Apache and MySQL Port Number in XAMPP Localhost</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! I&#39;m going to show you &lt;strong&gt;how to change the apache and mysql port number in xampp localhost&lt;/strong&gt;. In case you wonder why you should change the port number of a web server, here is the answer. It&#39;s not unlikely for you to run multiple PHP versions on a same machine or to run IIS or JBoss simultaneously with Apache.&lt;/p&gt;

&lt;p&gt;When you start a web server, it occupies the default HTTP port &#39;80&#39;. If you try to run the second one, it will fail since the port is already occupied. So unless you change the port for the latter, you can&#39;t run more than one web server at once. Below we will see the ways to change the port no. for apache and mysql.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;xampp change apache port number localhost&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKbz2FE8_G-0eveWhBRoLk5bU24I1Nf86ath8Qv1bMsXLAU1aB3qpyt77kvdHoD0rimGDjtp3BeOFZHZGntOhtvE5tn6bfhHPw7gt2PYc98AeCV-EZ4bBmDLuDd0PwFsuzqA8z6F3axj78/s1600/xampp-change-apache-port-number-localhost.png&quot; title=&quot;Change Apache Port in XAMPP&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;To Change Apache Port Number:&lt;/h2&gt;

&lt;p&gt;Stop Apache server and exit XAMPP control panel if it is already running.&lt;/p&gt;

&lt;h5&gt;First you must change the HTTP port.&lt;/h5&gt;

&lt;p&gt;Go to &lt;strong&gt;[path-to-xampp-folder]/apache/conf&lt;/strong&gt; folder and open &lt;strong&gt;http.conf&lt;/strong&gt; file.&lt;/p&gt;

&lt;p&gt;The default port for Apache is &#39;80&#39;. Unless you have changed it, this is the port number you must replace.&lt;/p&gt;

&lt;p&gt;Now look for the line,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
Listen 80
&lt;/pre&gt;

&lt;p&gt;And then change the port no. to some unused port like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
Listen 8012
&lt;/pre&gt;

&lt;p&gt;Then search for the line,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
ServerName localhost:80
&lt;/pre&gt;

&lt;p&gt;And replace &#39;80&#39; with the new port no like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
ServerName localhost:8012
&lt;/pre&gt;

&lt;p&gt;Save the file.&lt;/p&gt;

&lt;h5&gt;Next you must change the SSL port.&lt;/h5&gt;

&lt;p&gt;Open &lt;strong&gt;[path-to-xampp-folder]/apache/conf/extra/httpd-ssl.conf&lt;/strong&gt; file and search for the lines,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
Listen 443
&amp;lt;VirtualHost _default_:443&amp;gt;
ServerName localhost:433
&lt;/pre&gt;

&lt;p&gt;Replace &#39;443&#39; port with something else,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
Listen 444
&amp;lt;VirtualHost _default_:444&amp;gt;
ServerName localhost:444
&lt;/pre&gt;

&lt;p&gt;Save the file.&lt;/p&gt;

&lt;p&gt;Done! Now restart Apache and access the url &lt;code&gt;http://localhost:8012&lt;/code&gt; on browser. If everything goes fine, you will see the xampp home page.&lt;/p&gt;

&lt;blockquote&gt;Please remember to use the port number along with local host to access it. This is not required when you leave apache to run on the default port itself.&lt;/blockquote&gt;

&lt;h2&gt;To Change MySQL Port:&lt;/h2&gt;

&lt;p&gt;Just like Apache, you can also change the default port used by MySQL Server which is &#39;3306&#39;.&lt;/p&gt;

&lt;p&gt;To do this, go to &lt;strong&gt;[path-to-xampp-folder]/mysql/bin/&lt;/strong&gt; and open the file &lt;strong&gt;my.ini&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Locate the line containing &#39;3306&#39; no. and change it to &#39;3310&#39; or something else and save. Please make sure the new port number is not used by any other service.&lt;/p&gt;

&lt;blockquote&gt;You can use &#39;Netstat&#39; to check all used ports on your system.&lt;/blockquote&gt;

&lt;p&gt;That&#39;s it. You have successfully &lt;em&gt;changed the default port numbers of apache and mysql server on xampp server&lt;/em&gt;. The same procedure can be applied for &#39;WAMP&#39; and &#39;LAMP&#39; stacks. For LAMP, you can locate the files on &#39;usr/bin/apache&#39; directory.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;https://www.kodingmadesimple.com/2015/06/how-to-backup-restore-mysql-database-command-line.html&quot;&gt;How to Backup and Restore MySQL Database from Command Line&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/05/change-apache-mysql-port-number-xampp.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKbz2FE8_G-0eveWhBRoLk5bU24I1Nf86ath8Qv1bMsXLAU1aB3qpyt77kvdHoD0rimGDjtp3BeOFZHZGntOhtvE5tn6bfhHPw7gt2PYc98AeCV-EZ4bBmDLuDd0PwFsuzqA8z6F3axj78/s72-c/xampp-change-apache-port-number-localhost.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-6788633779945316850</guid><pubDate>Fri, 04 May 2018 16:04:00 +0000</pubDate><atom:updated>2018-05-04T21:34:08.967+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Conversions</category><category domain="http://www.blogger.com/atom/ns#">PDF</category><category domain="http://www.blogger.com/atom/ns#">php</category><title>How to Convert PDF to JPEG Image in PHP</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! Today let&#39;s see &lt;strong&gt;how to convert pdf to jpeg in php using imagick&lt;/strong&gt;. PHP offers some good native extensions for image processing. Imagick is one of those extensions with which we can easily create JPEG images from pdf without the need for third-party tools.&lt;/p&gt;

&lt;p&gt;The library does not need installation since it comes built-in with PHP. You just have to instantiate the class and use it. Plus it provides several customization options to create images. I suggest you to refer the official documentation for the complete list of functions.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;php convert pdf to jpeg&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihG7Se49duwhjzqLyvr6zKgGP5_M_R-SX0B9yln6mCP27EP-WZBVPVl8JNFvKXz5navEBy-CxkCaSTYHS7581lIHL5OIb91s3Mag-jNpLjohBUy4tlFDCVOC1gs-54ZcOOCcU0yyDl5c-R/s1600/php-convert-pdf-to-jpeg.jpg&quot; title=&quot;PDF To JPEG&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;PHP - Convert PDF File to JPEG:&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Imagick&lt;/strong&gt; is the native php extension to create and process images using the &lt;strong&gt;ImageMagick API&lt;/strong&gt;. To covert the pdf into jpeg with imagick, you must first read the image from the pdf file and then write it into an image. The following example converts all the pages in a pdf file into jpeg images.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
$imagick = new Imagick();
$imagick-&amp;gt;readImage(&#39;mypdf.pdf&#39;);
$imagick-&amp;gt;writeImages(&#39;myimage.jpg&#39;, false);
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;In the above snippet, we used two functions,&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;Function &lt;code&gt;readImage()&lt;/code&gt;, to read the image from the given file.&lt;/li&gt;
 &lt;li&gt;Function &lt;code&gt;writeImages()&lt;/code&gt;, to write an image or image sequence to the file. We have set the second parameter as &#39;false&#39;, which makes the pages to be split into a separate image file. For example, if there are 3 pages in the pdf, they will be saved as myimage-0.jpg, myimage-1.jpg and myimage-2.jpg.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;For Better Quality:&lt;/h3&gt;

&lt;p&gt;To obtain better image quality, use the &lt;code&gt;setResolution()&lt;/code&gt; method before reading the image.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$imagick-&amp;gt;setResolution(150, 150);
&lt;/pre&gt;

&lt;h2&gt;Converting Specific Page to JPEG:&lt;/h2&gt;

&lt;p&gt;In case you want to convert only a particular page in the pdf file, use the page number after the file name like this, &lt;code&gt;mypdf.pdf[0]&lt;/code&gt;. Please remember, the pages start from zero. It will just convert the first page of the pdf into image. Here&#39;s the example.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
$imagick = new Imagick();
$imagick-&amp;gt;readImage(&#39;mypdf.pdf[0]&#39;);
$imagick-&amp;gt;writeImages(&#39;page_one.jpg&#39;);
?&amp;gt;
&lt;/pre&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;
&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/convert-html-to-pdf-php-dompdf.html&quot;&gt;How to Convert HTML to PDF in PHP using DomPDF&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/dynamic-treeview-menu-php-mysql-ajax.html&quot;&gt;Create Dynamic Treeview with PHP, MySQL &amp; AJAX&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is really easy to &lt;em&gt;convert pdf to jpeg using the imagick extension&lt;/em&gt;. It offers a wide range of functions to create, edit and process images and support formats such as jpg, png, etc. I hope this tutorial is useful to you. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/05/convert-pdf-to-jpeg-php.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEihG7Se49duwhjzqLyvr6zKgGP5_M_R-SX0B9yln6mCP27EP-WZBVPVl8JNFvKXz5navEBy-CxkCaSTYHS7581lIHL5OIb91s3Mag-jNpLjohBUy4tlFDCVOC1gs-54ZcOOCcU0yyDl5c-R/s72-c/php-convert-pdf-to-jpeg.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-916922454050971903</guid><pubDate>Wed, 25 Apr 2018 14:40:00 +0000</pubDate><atom:updated>2018-04-25T20:10:43.533+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CodeIgniter</category><category domain="http://www.blogger.com/atom/ns#">CodeIgniter Tutorials</category><title>How to Create Custom Library in CodeIgniter</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi, today let&#39;s see &lt;strong&gt;how to create custom library in codeigniter&lt;/strong&gt;. CodeIgniter offers a rich set of libraries and helpers for robust application development. In general, a library is a class file used to group similar functionalities into a single file. Now we can do the same with helper but the libraries have their own object to store relevant data.&lt;/p&gt;

&lt;p&gt;Below I&#39;ll show you how to create your own class libraries in CI. You must store these library files inside the &#39;application/libraries&#39; folder. This will keep them separate from the native libraries of the framework.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;create custom library in codeigniter&quot; border=&quot;0&quot; data-original-height=&quot;328&quot; data-original-width=&quot;573&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy_39UP7xcdWC326N_aCyDs8dDX8-JoBzjLHdaXVRqo8MWkWZMlUJLTSw0Hu5vp79pADw-ViwoPUuDKq2nXNWnEqDgFZWQWsfJzfJaXVkeYU1RxeOppVqHS_4LbQTISgkEE_zwTbigPEXA/s1600/codeigniter-create-custom-library.jpg&quot; title=&quot;CodeIgniter Custom Library&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;CodeIgniter - Create Custom Library:&lt;/h2&gt;

&lt;p&gt;CodeIgniter is a flexible MVC framework and allows you to,&lt;/p&gt;

&lt;ol&gt;
 &lt;li&gt;Create new custom libraries.&lt;/li&gt;
 &lt;li&gt;Extend existing libraries to include additional functionalities to them.&lt;/li&gt;
 &lt;li&gt;Replace native libraries completely with your own version.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I&#39;m going to show you an example where I create a custom library to export the database table as a json string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-1)&lt;/strong&gt; Create a library named &#39;Mylib.php&#39; inside the &#39;application/libraries&#39; folder. Make sure the file name matches the class name.&lt;/p&gt;

&lt;h3&gt;Mylib.php&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php if (! defined(&#39;BASEPATH&#39;)) exit(&#39;No direct script access allowed&#39;);

class Mylib
{
    public function to_json($tblname)
    {
        $CI =&amp; get_instance();
        $CI-&amp;gt;load-&amp;gt;database();
        $query = $CI-&amp;gt;db-&amp;gt;get($tblname);
        return json_encode($query-&amp;gt;result(), JSON_PRETTY_PRINT);
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;In the &#39;Mylib&#39; class, I have added a member function &lt;code&gt;to_json()&lt;/code&gt; which takes up a database table name as a parameter, fetch and return the data as json.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-2)&lt;/strong&gt; Next we need a controller file to test the library. So create a controller &#39;TestController.php&#39; within &#39;application/controllers&#39; folder.&lt;/p&gt;

&lt;h3&gt;TestController.php&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php if (! defined(&#39;BASEPATH&#39;)) exit(&#39;No direct script access allowed&#39;);

class TestController extends CI_Controller
{
    function __construct()
    {
        parent::__construct();
    }
    
    function index()
    {
        // code
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-3)&lt;/strong&gt; Now load the library within the controller&#39;s &lt;code&gt;index()&lt;/code&gt; function.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$this-&amp;gt;load-&amp;gt;library(&#39;mylib&#39;);
&lt;/pre&gt;

&lt;p&gt;You can also auto load the library inside &#39;application/config/autoload.php&#39; file. Just look for the line, &lt;code&gt;$autoload[&#39;libraries&#39;]&lt;/code&gt; and add the library name. Auto loading will make it available for the entire application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-4)&lt;/strong&gt; Then call the to_json() function to export the database table as json.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$json = $this-&amp;gt;mylib-&amp;gt;to_json(&#39;customers&#39;);
print &#39;&amp;lt;pre&amp;gt;&#39; . $json . &#39;&amp;lt;/pre&amp;gt;&#39;;
&lt;/pre&gt;

&lt;p&gt;Now running the &#39;TestController&#39; will output the data from the given table as a json string on the browser.&lt;/p&gt;

&lt;p&gt;This is just a simple example of what a custom library can do.&lt;/p&gt;

&lt;h2&gt;Extending a Native Library:&lt;/h2&gt;

&lt;p&gt;Sometimes you may want to include some additional functions to a native library. In such case you can just extend the library like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
class MY_Email extends CI_Email
{

    public function __construct()
    {
        parent::__construct();
    }
    
    public function my_function()
    {
        // code goes here
    }
}
&lt;/pre&gt;

&lt;p&gt;Please note that while extending a library you must set the prefix &lt;code&gt;&#39;MY_&#39;&lt;/code&gt; before the class name.&lt;/p&gt;

&lt;p&gt;And you can change this prefix inside &#39;application/config/config.php&#39; file. Just search for the below line and replace it with your choice of prefix.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$config[&#39;subclass_prefix&#39;] = &#39;MY_&#39;;
&lt;/pre&gt;

&lt;p&gt;To use &lt;code&gt;my_function()&lt;/code&gt; in your application, load the &#39;email&#39; library like you always do and access the function like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$this-&amp;gt;load-&amp;gt;library(&#39;email&#39;);
$this-&amp;gt;email-&amp;gt;my_function();
&lt;/pre&gt;

&lt;h2&gt;Replacing the Native Library:&lt;/h2&gt;

&lt;p&gt;In case you want to rewrite an entire native library, you can simply replace it with your own version. For example, to replace the &#39;Email&#39; library, create a file &#39;Email.php&#39; inside &#39;application/libraries&#39; folder and declare the class like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
class CI_Email
{
    // code
}
&lt;/pre&gt;

&lt;p&gt;And to use the class, you can simply load it on your controller or view like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$this-&amp;gt;load-&amp;gt;library(&#39;email&#39;);
&lt;/pre&gt;

&lt;strong&gt;Also Read:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/codeigniter-generate-pdf-from-view-dompdf.html&quot;&gt;How to Generate PDF in CodeIgniter using DomPDF&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/ajax-pagination-codeigniter.html&quot;&gt;How to Create AJAX Pagination in CodeIgniter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That explains about &lt;em&gt;creating custom libraries in codeigniter&lt;/em&gt;. I have also discussed about other ways of working with libraries. Just make sure to place all your library files inside &#39;application&#39; &amp;gt; &#39;libraries&#39; path and you are good to go. I hope you find this tutorial useful. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/04/create-custom-library-codeigniter.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhy_39UP7xcdWC326N_aCyDs8dDX8-JoBzjLHdaXVRqo8MWkWZMlUJLTSw0Hu5vp79pADw-ViwoPUuDKq2nXNWnEqDgFZWQWsfJzfJaXVkeYU1RxeOppVqHS_4LbQTISgkEE_zwTbigPEXA/s72-c/codeigniter-create-custom-library.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-2042739595726484239</guid><pubDate>Wed, 18 Apr 2018 14:37:00 +0000</pubDate><atom:updated>2018-04-18T20:07:30.770+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CSV</category><category domain="http://www.blogger.com/atom/ns#">CSV to MySQL</category><category domain="http://www.blogger.com/atom/ns#">MySQL</category><title>How to Import CSV File into MySQL with LOAD DATA INFILE</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;I tried to &lt;a href=&quot;http://www.kodingmadesimple.com/2015/07/import-csv-file-into-mysql-database-php-script.html&quot;&gt;import a csv file into mysql with php script&lt;/a&gt;. It is a simple solution if you have a small set of data to import. But if you have hundreds of thousands of records, don&#39;t even think about it. You need something different to read through a large dataset quickly. MySQL&#39;s &lt;strong&gt;LOAD DATA INFILE&lt;/strong&gt; command works like a charm and can be executed from the command line.&lt;/p&gt;

&lt;p&gt;Using &lt;em&gt;LOAD DATA INFILE&lt;/em&gt; allows you to load csv or any other delimited data file to the mysql table with a single command. It comes with several options and we will see below what they are and how to use them to import the csv data set into the mysql table.&lt;/p&gt;

&lt;h2&gt;Using LOAD DATA INFILE Command:&lt;/h2&gt;

&lt;p&gt;The LOAD DATA INFILE command in mysql loads data from a file into the table at high speed. The file path specified must be absolute or relative.&lt;/p&gt;

&lt;h3&gt;1. Importing CSV File into MySQL:&lt;/h3&gt;

&lt;p&gt;Let&#39;s say we have a mysql table &lt;em&gt;&#39;customers&#39;&lt;/em&gt; with the following structure.&lt;/p&gt;

&lt;h5&gt;MySQL Table: Customers&lt;/h5&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
CREATE TABLE `customers`(
    `id` INT(8) NOT NULL ,
    `name` VARCHAR(30) NOT NULL ,
    `email` VARCHAR(40) NOT NULL ,
    `location` VARCHAR(25) NOT NULL ,
    PRIMARY KEY (`id`)
);
&lt;/pre&gt;

&lt;p&gt;And a csv file &lt;em&gt;customers.csv&lt;/em&gt; with data that we want to insert into the &#39;customers&#39; table.&lt;/p&gt;

&lt;h5&gt;CSV File: Customers.csv&lt;/h5&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;csv file to import into mysql&quot; border=&quot;0&quot; data-original-height=&quot;186&quot; data-original-width=&quot;575&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaJXOkWIQCpZ7sntx-ucGKIM5jSwk_OBZED29BzllUp_qOgpe4cHl3E4vqfyHgkOAXYDcigQtnMbd0_6w9r9zwMOVHqkobuR3TEEHo-7O8_gNiUl08SgR7mdR046I8oiXTTHFznnWUcVL4/s1600/csv-file-to-import-into-mysql.png&quot; title=&quot;CSV File&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Now to import the csv data into the table, use the following sql statement.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
LOAD DATA INFILE &#39;c:/tmp/customers.csv&#39;
INTO TABL    E customers
FIELDS TERMINATED BY &#39;,&#39;
OPTIONALLY ENCLOSED BY &#39;&quot;&#39;
LINES TERMINATED BY &#39;\r\n&#39;
IGNORE 1 LINES;
&lt;/pre&gt;

&lt;p&gt;Executing the above sql will import records to the given &#39;customers&#39; table.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;customers mysql table after running load data infile command&quot; border=&quot;0&quot; data-original-height=&quot;164&quot; data-original-width=&quot;469&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinXjNOLtrFPXSTPH4NiyrikakTG_eBV5e6DCKLpbeVCLPtIJtZLXUmAjBicVa6h3tHoqxMQKU4d_OODoijTKhh93bDYTuvrhv2JBUdV9LNPIPuK0oCkWDZfCQCbmLdX1luo1UqxSchidkg/s1600/customers-mysql-table.png&quot; title=&quot;MySQL Table&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Our csv file has a column header as the first row, so we used the option &lt;code&gt;IGNORE 1 LINES&lt;/code&gt; which will skip the first row. If you don&#39;t have the column header, don&#39;t use it.&lt;/p&gt;

&lt;p&gt;Also make sure the file path is correct. You can use the format &#39;c:/tmp/customers.csv&#39; or &#39;c:\\tmp\\customers.csv&#39;.&lt;/p&gt;

&lt;p&gt;This method will only work when your mysql table has the same sequence of columns as of the csv file.&lt;/p&gt;

&lt;h3&gt;2. Importing File with Different Column Sequence from Table:&lt;/h3&gt;

&lt;p&gt;Consider the scenario where your table and csv file column sequence are different. In this case, you must explicitly specify the order of the column name to ensure that the data is imported correctly.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
LOAD DATA INFILE &#39;c:/tmp/customers.csv&#39;
INTO TABLE tbl_customers
FIELDS TERMINATED BY &#39;,&#39;
OPTIONALLY ENCLOSED BY &#39;&quot;&#39;
LINES TERMINATED BY &#39;\r\n&#39;
IGNORE 1 LINES
(id,name,email,location);
&lt;/pre&gt;

&lt;h3&gt;3. Importing Data to Remote MySQL Database Server:&lt;/h3&gt;

&lt;p&gt;If you have your file on the local machine and not on the server, use the word &lt;code&gt;LOCAL&lt;/code&gt;. This will import file from the client (local system) to a remote mysql database server.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
LOAD DATA LOCAL INFILE &#39;c:/tmp/customers.csv&#39;
INTO TABLE tbl_customers
FIELDS TERMINATED BY &#39;,&#39;
OPTIONALLY ENCLOSED BY &#39;&quot;&#39;
LINES TERMINATED BY &#39;\r\n&#39;
IGNORE 1 LINES
(id,name,email,location);
&lt;/pre&gt;

&lt;p&gt;When you include the LOCAL option, the file is expected to be located on the client and not on the server.&lt;/p&gt;

&lt;p&gt;You can also use the &lt;code&gt;mysqlimport&lt;/code&gt; utility to load csv data into the database. It&#39;s very similar to LOAD DATA INFILE, except that mysqlimport supports multiple file loading and the latter does not.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/find-second-highest-salary-mysql.html&quot;&gt;How to Find the Second Highest Salary in MySQL&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2015/06/how-to-backup-restore-mysql-database-command-line.html&quot;&gt;Backup &amp; Restore MySQL Database with Command Line&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have a large dataset to import, go for the LOAD DATA INFILE command, as it is extremely faster than doing it with any other script. I hope this tutorial is useful to you. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/04/import-csv-file-into-mysql-load-data-infile.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaJXOkWIQCpZ7sntx-ucGKIM5jSwk_OBZED29BzllUp_qOgpe4cHl3E4vqfyHgkOAXYDcigQtnMbd0_6w9r9zwMOVHqkobuR3TEEHo-7O8_gNiUl08SgR7mdR046I8oiXTTHFznnWUcVL4/s72-c/csv-file-to-import-into-mysql.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-6115462318024600019</guid><pubDate>Mon, 09 Apr 2018 14:32:00 +0000</pubDate><atom:updated>2018-04-09T20:02:07.940+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">html</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><category domain="http://www.blogger.com/atom/ns#">jQuery Plugin</category><category domain="http://www.blogger.com/atom/ns#">Select2</category><title>How to Add Select All Options to jQuery Select2 Plug-in</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi, in this post let&#39;s see &lt;strong&gt;how to add select all options to jQuery Select2 plugin&lt;/strong&gt;. Select2 is an excellent alternative to the standard HTML selection box that supports all its functions and provides greater flexibility. The plug-in is easy to setup and use. It supports multiple selection options where the selected elements will be added as pills to the top text box. You can also tag, search and load remote data-sets to select2 control.&lt;/p&gt;

&lt;p&gt;Below we will see how to use select2 in your web projects, and select all options at once by ticking a check box using jquery.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;jquery select2 select all options on click&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ7bVCLuRupmBbStylnF_9SVZQxbMezezLsV00eavBHEikyBeYwugBmbpgfg-IR_2XdBMau0lKbRMWHaB-cZheYzFyyHg7_R0DL4BWdjDpOdU6w2QEcbgkkc0_EBAe4bS1D5bhyL9zvewW/s1600/jquery-select2-select-all-options.png&quot; title=&quot;Select2 Select All Options in jQuery&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;How to Use Select2 jQuery Plug-in?&lt;/h2&gt;

&lt;p&gt;To implement Select2 plug-in in your projects, create a regular drop-down box with html markup as usual.&lt;/p&gt;

&lt;h3&gt;HTML:&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;select id=&quot;states&quot; style=&quot;width:300px&quot;&amp;gt;
    &amp;lt;option&amp;gt;Alaska&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Arizona&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;California&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Florida&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Hawaii&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;illinois&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Michigan&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;North Dacota&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Ohio&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Washington&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;
&lt;/pre&gt;

&lt;p&gt;This would produce a select box like this,&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;standard html select box example&quot; border=&quot;0&quot; data-original-height=&quot;192&quot; data-original-width=&quot;307&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi798p5WyI4kChfDmAmn6fd1tM22Vn313_ieh0DpeEXOAA6Yze1RjgrD80FZssOieTIs5j7-LIjz2t5Qotd9rZT4zVprzFF2UdXuLFesiimbNrWJfM6sMqTZXmPU4kl4MCTrBye5L_NMj-S/s1600/standard-html-select-example.png&quot; title=&quot;standard html select&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Now load the library files for jquery and select2 on the html page. Do it only once on a page.&lt;/p&gt;

&lt;h3&gt;CSS:&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;link href=&quot;https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/css/select2.min.css&quot; rel=&quot;stylesheet&quot; /&amp;gt;
&lt;/pre&gt;

&lt;h3&gt;JS:&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;script src=&quot;https://code.jquery.com/jquery-2.1.1.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/js/select2.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Finally bind the &lt;code&gt;select2()&lt;/code&gt; method to the dropdown in this way,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
$(document).ready(function() {
    $(&#39;#states&#39;).select2();
});
&lt;/pre&gt;

&lt;p&gt;It will initialize the select2 control and convert the plain dropdown to this,&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;select2 single select example&quot; border=&quot;0&quot; data-original-height=&quot;270&quot; data-original-width=&quot;307&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsEvRsQA_ai9Yga8jG6Fr6tYiBjKkET9ilOvgFbXPyR1Xw4r9_wVTj6Wfm6CoWumrcegUr_EW8G2_pixy3U_UrnZ8PnQjI6aWHKs88psrUd6tTafll_RjLjWoo8k43QRukHWNFQ0LOcXLd/s1600/select2-single-select-example.png&quot; title=&quot;Select2 Single Select Option&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Please note that you must wrap your code within the &lt;code&gt;$(document).ready()&lt;/code&gt; block. This will ensure that the DOM is ready before initializing the select2 control.&lt;/p&gt;

&lt;h2&gt;Select2 Multiple Select Box:&lt;/h2&gt;

&lt;p&gt;Select2 also supports multiple selection option. All you have to do is to declare the &lt;code&gt;multiple&lt;/code&gt; attribute to the input. This will add the selected options as pills to the text box at the top of the control.&lt;/p&gt;

&lt;h3&gt;Example:&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;select id=&quot;states&quot; multiple style=&quot;width:300px&quot;&amp;gt;
    &amp;lt;option&amp;gt;Alaska&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Arizona&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;California&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Florida&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Hawaii&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;illinois&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Michigan&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;North Dacota&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Ohio&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Washington&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;

&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
$(document).ready(function() {
    $(&#39;#states&#39;).select2();
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;The above example will produce a dropdown box like this,&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;select2 multi select example&quot; border=&quot;0&quot; data-original-height=&quot;242&quot; data-original-width=&quot;309&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjwA1kInbHwYTBjxb7Y1Ufye3naiZ3kS1IlpeklZlK-bix68OGp9tyOYRa4suPlOXKZHi2vnzEjpA5p7a8URlzHFYsY-Xrlz0d3gHNjTtNdlodjPsMYtmEMOM99fHU5bAbCO-dp2NF7tLjY/s1600/select2-multi-select-example.png&quot; title=&quot;Select2 Multi Select&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;Add Select All Option to jQuery Select2:&lt;/h2&gt;

&lt;p&gt;Select2 also supports selecting all options at once from the list. Here we&#39;ll see how to select all the options when the user ticks the &lt;strong&gt;&#39;Select All&#39;&lt;/strong&gt; checkbox.&lt;/p&gt;

&lt;p&gt;First create the markup for the multi-value select box and a check box for selecting all option.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;select id=&quot;states&quot; multiple style=&quot;width:300px&quot;&amp;gt;
    &amp;lt;option&amp;gt;Alaska&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Arizona&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;California&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Florida&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Hawaii&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;illinois&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Michigan&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;North Dacota&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Ohio&amp;lt;/option&amp;gt;
    &amp;lt;option&amp;gt;Washington&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;

&amp;lt;input id=&quot;chkall&quot; type=&quot;checkbox&quot; &amp;gt;Select All
&lt;/pre&gt;

&lt;p&gt;Now add this java script to the page.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
$(document).ready(function() {
    $(&#39;#states&#39;).select2();
    
    $(&quot;#chkall&quot;).click(function(){
        if($(&quot;#chkall&quot;).is(&#39;:checked&#39;)){
            $(&quot;#states &amp;gt; option&quot;).prop(&quot;selected&quot;, &quot;selected&quot;);
            $(&quot;#states&quot;).trigger(&quot;change&quot;);
        } else {
            $(&quot;#states &amp;gt; option&quot;).removeAttr(&quot;selected&quot;);
            $(&quot;#states&quot;).trigger(&quot;change&quot;);
        }
    });
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;The above script will be executed by &lt;code&gt;onclick()&lt;/code&gt; event of the check box. If checked, the script will set all the options of the select control as &lt;code&gt;selected&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you think this will alone do the job, you&#39;re wrong. This will simply keep all items in the dropdown selected, but will not add the selected items to the top of the control. For that we have to explicitly trigger the &lt;strong&gt;&#39;change&#39;&lt;/strong&gt; event.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;select2 select all options example&quot; border=&quot;0&quot; data-original-height=&quot;297&quot; data-original-width=&quot;389&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiugaZlxdERXrTNVUZpeLwi9R9rJRjEes2UtGk2fq-idEnexuW_zlhgPpwPW0GkS_-qiUYM6z2i_Lm2wdQmhv3n4TLGnmwbB_fQZZHMvkxSh1fmHqy0w2OQvezA2mDqGIXshsOqvsxbxaNM/s1600/select2-select-all-options-example.png&quot; title=&quot;Select2 Select All Options&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Read other tutorials of select2,&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/add-images-to-dropdown-list-jquery.html&quot;&gt;How to Add Images to Dropdown box using jQuery Select2&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/02/codeigniter-autocomplete-search-from-database-ajax.html&quot;&gt;AJAX Autocomplete Search from Database with Select2&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That explains about jquery select2 and selecting all the options at once on click of the checkbox. The plugin offers so many customizations and adds flexibility to the standard html select box. I hope you like this tutorial. Meet you in another interesting post. Good day!&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/04/select-all-options-jquery-select2.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhJ7bVCLuRupmBbStylnF_9SVZQxbMezezLsV00eavBHEikyBeYwugBmbpgfg-IR_2XdBMau0lKbRMWHaB-cZheYzFyyHg7_R0DL4BWdjDpOdU6w2QEcbgkkc0_EBAe4bS1D5bhyL9zvewW/s72-c/jquery-select2-select-all-options.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-6491908406046008965</guid><pubDate>Fri, 06 Apr 2018 10:30:00 +0000</pubDate><atom:updated>2018-04-06T19:25:22.068+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">Send Email</category><category domain="http://www.blogger.com/atom/ns#">SMTP</category><title>Send HTML Email in PHP via SMTP</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! Welcome to &lt;a href=&quot;http://www.kodingmadesimple.com/&quot;&gt;Koding Made Simple&lt;/a&gt;.  Today we&#39;ll see how to &lt;strong&gt;send html email in php&lt;/strong&gt;.  PHP&#39;s mail() function is simple and effective and let you send emails with text/html contents and with attachments.  Though it has some shortcomings compared to other mailer libraries like &lt;strong&gt;PHPMailer&lt;/strong&gt;, it does the job and comes in-built with PHP package.  Plain text emails are good enough, but the ability to send html emails is more powerful in email marketing and other promotions.&lt;/p&gt;

&lt;p&gt;HTML emails include html tags and let you add images, format texts and other eye-catching call-to-action buttons etc.  But you have to add additional headers for mailing them.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;php-send-html-email-via-smtp&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsZJaMliuZZ71pbgGXvQJu79aUzHbblB3UD517rZgUkwKjLiY3blD6KOY4CTwDgjWWx1_ZriP-qK3iYsLq6wEfAUtAdTCJsfq0wVKABRo3UjZ6cKEFtByDO3Zc2PigqxC6n2kX6fGkBnzq/s1600/php-send-html-email-via-smtp.jpg&quot; title=&quot;Send HTML Email in PHP&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;Using SMTP for Sending Email&lt;/h2&gt;

&lt;p&gt;You can send mails via third party Mail Servers but you need authentication first.  That is if you want to send email via Gmail in php, then you must have a working gmail account and provide the accounts email-id and password for authentication.  We&#39;ll see how to set up the php configuration for &lt;a href=&quot;http://www.kodingmadesimple.com/2015/03/how-to-send-email-in-codeigniter-smtp.html&quot;&gt;sending email via gmail smtp server&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;How to Send HTML Email in PHP Using Gmail SMTP&lt;/h2&gt;

&lt;p&gt;You need to change the settings in two places i.e., &lt;code&gt;php.ini&lt;/code&gt; and &lt;code&gt;sendmail.ini&lt;/code&gt; files.  You must remove the &lt;code&gt;;&lt;/code&gt; at the starting of the line to enable the settings in these files.  Please note the configuration is given for the xampp package. Open &#39;php.ini&#39; file located at &lt;code&gt;C:\xampp\php\php.ini&lt;/code&gt; and edit the settings like below.&lt;/p&gt;

&lt;h3&gt;php.ini&lt;/h3&gt;

&lt;pre class=&quot;prettyprint codebk&quot;&gt;
[mail function]
SMTP = smtp.gmail.com
smtp_port = 587
sendmail_from = christmascontest@gmail.com
sendmail_path = &quot;\&quot;C:\xampp\sendmail\sendmail.exe\&quot; -t&quot;
&lt;/pre&gt;

Next open the &#39;sendmail.ini&#39; file located at &lt;code&gt;C:\xampp\sendmail\sendmail.ini&lt;/code&gt; and make the below changes.

&lt;h3&gt;sendmail.ini&lt;/h3&gt;

&lt;pre class=&quot;prettyprint codebk&quot;&gt;
smtp_server = smtp.gmail.com
smtp_port = 587
auth_username = christmascontest@gmail.com
auth_password = christmascontest
force_sender = christmascontest@gmail.com
&lt;/pre&gt;

&lt;p&gt;Save the files and restart apache server for the changes to reflect.  Now you are ready to send send html email using php &lt;code&gt;mail()&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Create a php file and write down the below php mailer code to it and save.&lt;/p&gt;

&lt;h2&gt;PHP Code for Sending HTML Email&lt;/h2&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
// from email
$from = &#39;christmascontest@gmail.com&#39;; // change this
// to email
$to = &#39;sally@somedomain.com, justin@somedomain.com, parker@somedomain.com&#39;; // change this
// subject
$subject = &#39;Christmas Contest Announcement&#39;;

// html message
$htmlmsg = &#39;&amp;lt;html&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;title&amp;gt;Christmas Contest Winners&amp;lt;/title&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body&amp;gt;
        &amp;lt;h1&amp;gt;Hi! We are glad to announce the Christmas contest winners...&amp;lt;/h1&amp;gt;
        &amp;lt;table&amp;gt;
            &amp;lt;tr style=&quot;background-color: #EEE;&quot;&amp;gt;
                &amp;lt;th width=&quot;25%&quot;&amp;gt;#&amp;lt;/th&amp;gt;
                &amp;lt;th width=&quot;35%&quot;&amp;gt;Ticket No.&amp;lt;/th&amp;gt;
                &amp;lt;th&amp;gt;Name&amp;lt;/th&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
                &amp;lt;td&amp;gt;#1&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;P646MLDO808K&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;Sally&amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr style=&quot;background-color: #EEE;&quot;&amp;gt;
                &amp;lt;td&amp;gt;#2&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;DFJ859LV9D5U&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;Parker&amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
            &amp;lt;tr&amp;gt;
                &amp;lt;td&amp;gt;#3&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;AU30HI8IHL96&amp;lt;/td&amp;gt;
                &amp;lt;td&amp;gt;Justin&amp;lt;/td&amp;gt;
            &amp;lt;/tr&amp;gt;
        &amp;lt;/table&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&#39;;

// set content type header for html email
$headers  = &#39;MIME-Version: 1.0&#39; . &quot;\r\n&quot;;
$headers .= &#39;Content-type: text/html; charset=UTF-8&#39; . &quot;\r\n&quot;;

// set additional headers
$headers .= &#39;From: Christmas Contest &amp;lt;christmascontest@gmail.com&amp;gt;&#39; . &quot;\r\n&quot;;
$headers .= &#39;Cc: contestadmin@gmail.com&#39; . &quot;\r\n&quot;;

// send email
if (mail($to, $subject, $htmlmsg, $headers))
    echo &quot;Email sent successfully!&quot;;
else
    echo &quot;Error sending email! Please try again later...&quot;;
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Change &lt;code&gt;$from&lt;/code&gt; to your gmail-id and &lt;code&gt;$to&lt;/code&gt; variable to the recipients email-id.&lt;/p&gt;

&lt;p&gt;Plus the code includes content type header which is a must for sending html emails and additional headers should be appended with &lt;code&gt;CRLF&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;Note:&lt;/u&gt;&lt;/strong&gt; If you have enabled two-way authentication for Google account then please disable it for this code to work.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;That&#39;s all about sending html email in php via smtp server. &lt;/em&gt;&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;
&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/php-send-email-smtp-phpmailer.html&quot;&gt;How to Send Email in PHP using PHPMailer&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2015/12/how-to-build-simple-web-crawler-in-php.html&quot;&gt;How to Build a Basic Web Crawler in PHP&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;br/&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2016/01/send-html-email-in-php-via-smtp.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsZJaMliuZZ71pbgGXvQJu79aUzHbblB3UD517rZgUkwKjLiY3blD6KOY4CTwDgjWWx1_ZriP-qK3iYsLq6wEfAUtAdTCJsfq0wVKABRo3UjZ6cKEFtByDO3Zc2PigqxC6n2kX6fGkBnzq/s72-c/php-send-html-email-via-smtp.jpg" height="72" width="72"/><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-1488152314137192556</guid><pubDate>Mon, 02 Apr 2018 13:22:00 +0000</pubDate><atom:updated>2018-04-02T18:52:07.938+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">html</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><title>How to Disable Mouse Right Click using jQuery</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Content theft is a serious issue faced by many website / blog owners. This can be limited to a certain level by disabling right click on websites. Disabling mouse right-click will prevent the context menu from appearing, there by preventing the page contents from being copied. Although it is not recommended as the best practice, it is certainly feasible.&lt;/p&gt;

&lt;p&gt;It is very easy to disable the right click on your site using jquery. You can do it at page level or element level. You have to capture and &lt;a href=&quot;http://www.kodingmadesimple.com/2017/03/disable-click-event-jquery.html&quot;&gt;cancel the event&lt;/a&gt; inside the event handler. We will see how to do it.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;jquery disable mouse right click cut copy paste&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsrZXIz7aToAM6qHWAq-G3dO-qo1YBGmdYPXyI4JUip33sTrFX0jOK8-mM1TBgwjuXC1ABOsFhy75cqWscuJM3FiMa2i8U0yekYc55K75Jq9OSFbTetX7_5Ichg3EGQxBH_qACkR9Z_alv/s1600/jquery-disable-mouse-right-click.png&quot; title=&quot;Disable Context Menu in jQuery&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;jQuery - Disable Right Click Context Menu:&lt;/h2&gt;

&lt;p&gt;You can avoid copying the contents of your website in two ways. One is to disable the right-click context menu altogether and the other is to simply disable the cut, copy and paste operations.&lt;/p&gt;

&lt;p&gt;1) To disable the right-click event on the entire web page, use this script,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
$(document).ready(function(){
    $(this).on(&#39;contextmenu&#39;, function(e){
        e.preventDefault();
    });
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;In the above script, the method &lt;code&gt;on()&lt;/code&gt; attaches the &lt;strong&gt;&#39;contextmenu&#39;&lt;/strong&gt; event handler to the document. And the &lt;code&gt;preventDefault()&lt;/code&gt; method prevents the default action of the element from happening; here it stops the context menu from showing up.&lt;/p&gt;

&lt;p&gt;2) To disable context-menu on mouse right click only on part of the web page, use the element id, class or the element itself.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
$(document).ready(function(){
    $(&#39;#id&#39;).on(&#39;contextmenu&#39;, function(e){
        e.preventDefault();
    });
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;3) To disable right click context menu on the whole page but on the editable element like textarea, use this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
$(document).ready(function(){
    $(this).on(&#39;contextmenu&#39;, function(e){
        if(e.target.nodeName != &quot;TEXTAREA&quot;){
            e.preventDefault();
        }
    });
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;h2&gt;Disable Cut, Copy &amp; Paste on Webpage:&lt;/h2&gt;

&lt;p&gt;The first method will only stop users from copy pasting the contents using mouse. But they can still fire keyboard shortcuts such as &lt;code&gt;CTRL+X&lt;/code&gt; (cut), &lt;code&gt;CTRL+C&lt;/code&gt; (copy), &lt;code&gt;CTRL+V&lt;/code&gt; (paste).&lt;/p&gt;

&lt;p&gt;1) To disable just the cut, copy and paste features on your web page, use this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
$(document).ready(function(){
    $(this).on(&#39;cut copy paste&#39;, function(e){
        return false;
    });
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;2) To disable cut, copy and paste operations on specific page elements, use this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
$(document).ready(function(){
    $(&#39;#code&#39;).on(&#39;cut copy paste&#39;, function(e){
        return false;
    });
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/add-images-to-dropdown-list-jquery.html&quot;&gt;How to Insert Images to Dropdown List with jQuery&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/02/jquery-animated-typing-effect-typed-js.html&quot;&gt;How to Create Animated Typing Effect using jQuery&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That&#39;s a pretty nifty solution for &lt;em&gt;disabling right click on the mouse&lt;/em&gt;. In jquery you can use both bind() and on() methods to attach the event handler to an element. Since &#39;bind&#39; is deprecated from v3.0, use &#39;on&#39; from here on. I hope this tutorial is useful for you. Please share it on your social circle if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/04/disable-mouse-right-click-jquery.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsrZXIz7aToAM6qHWAq-G3dO-qo1YBGmdYPXyI4JUip33sTrFX0jOK8-mM1TBgwjuXC1ABOsFhy75cqWscuJM3FiMa2i8U0yekYc55K75Jq9OSFbTetX7_5Ichg3EGQxBH_qACkR9Z_alv/s72-c/jquery-disable-mouse-right-click.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-5254338806006956641</guid><pubDate>Fri, 30 Mar 2018 14:44:00 +0000</pubDate><atom:updated>2018-03-30T20:14:47.528+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">html</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><category domain="http://www.blogger.com/atom/ns#">jQuery Plugin</category><category domain="http://www.blogger.com/atom/ns#">Select2</category><title>How to Add Images to Dropdown List using jQuery</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! In this post, let&#39;s see &lt;strong&gt;how to add images to dropdown list using jquery&lt;/strong&gt;. I had a form with a drop-down element for the list of countries and wanted to insert the corresponding country flag before each country name. But HTML does not support the addition of elements to select box. Then I found some CSS hack but this method is not compatible with all browsers. Finally, I decided to go with java script and found a fairly neat solution.&lt;/p&gt;

&lt;p&gt;Actually, it is a jquery plugin called &#39;select2&#39;. It includes the &lt;a href=&quot;http://www.kodingmadesimple.com/2016/02/drop-down-list-with-search-using-jquery-example.html&quot;&gt;autocomplete feature to dropdown list&lt;/a&gt;, but also allows you to add icons to those select options. Below, I&#39;ll show you how to use the select2 add-on to insert country flags before the country names in a drop-down list.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;jquery add images to dropdown list&quot; border=&quot;0&quot; data-original-height=&quot;324&quot; data-original-width=&quot;569&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWnXefNKT1-j_UIyg8H6XnjNvr47Xnmnn1mtVAHJDIQEnNBN6UZz2rH-nZr3-NroJy03yQMEj2g3mkIQJYW6_u8ATO8wev-PU2IPgdtdEe-I4stPAJPNIjy977ueoQD2QZFhQJClOhSTaQ/s1600/jquery-add-images-to-dropdown-list.png&quot; title=&quot;Insert Images to Dropdown List&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;jQuery - Adding Images to the Dropdown List:&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;STEP-1)&lt;/strong&gt; First load the &#39;jQuery&#39; and &#39;Select2&#39; libraries on the Web page. You need to add both &#39;css&#39; and &#39;js&#39; files of the plugin.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;link href=&quot;https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/css/select2.min.css&quot; rel=&quot;stylesheet&quot; /&amp;gt;

&amp;lt;script src=&quot;https://code.jquery.com/jquery-2.1.1.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
&amp;lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2-rc.1/js/select2.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-2)&lt;/strong&gt; Next, load the library for country flag icons. This will help us to display images of flags of all countries.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;link href=&quot;https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/0.8.2/css/flag-icon.min.css&quot; rel=&quot;stylesheet&quot; /&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-3)&lt;/strong&gt; Now create an empty drop down element to add the country names and flags.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;select id=&quot;countries&quot;&amp;gt;
    &amp;lt;option&amp;gt;&amp;lt;/option&amp;gt;
&amp;lt;/select&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-4)&lt;/strong&gt; Finally the JavaScript. This is the main part of the task. Here we have to create a JS array that contains all the country names and their IDs and pass it to the drop-down element that we created in the previous step.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
$(document).ready(function() {
    var options = [
        { id: &#39;AF&#39;, text: &#39;Afghanistan&#39;},{ id: &#39;AX&#39;, text: &#39;Aland Islands&#39;},{ id: &#39;AL&#39;, text: &#39;Albania&#39;},{ id: &#39;DZ&#39;, text: &#39;Algeria&#39;},{ id: &#39;AS&#39;, text: &#39;American Samoa&#39;},
        { id: &#39;AD&#39;, text: &#39;Andorra&#39;},{ id: &#39;AO&#39;, text: &#39;Angola&#39;},
        { id: &#39;AI&#39;, text: &#39;Anguilla&#39;},{ id: &#39;AQ&#39;, text: &#39;Antarctica&#39;},{ id: &#39;AG&#39;, text: &#39;Antigua And Barbuda&#39;},
        { id: &#39;AR&#39;, text: &#39;Argentina&#39;},{ id: &#39;AM&#39;, text: &#39;Armenia&#39;},{ id: &#39;AW&#39;, text: &#39;Aruba&#39;},
        { id: &#39;AU&#39;, text: &#39;Australia&#39;},{ id: &#39;AT&#39;, text: &#39;Austria&#39;},{ id: &#39;AZ&#39;, text: &#39;Azerbaijan&#39;},{ id: &#39;BS&#39;, text: &#39;Bahamas&#39;},{ id: &#39;BH&#39;, text: &#39;Bahrain&#39;},{ id: &#39;BD&#39;, text: &#39;Bangladesh&#39;},{ id: &#39;BB&#39;, text: &#39;Barbados&#39;},{ id: &#39;BY&#39;, text: &#39;Belarus&#39;},{ id: &#39;BE&#39;, text: &#39;Belgium&#39;},
        { id: &#39;BZ&#39;, text: &#39;Belize&#39;},{ id: &#39;BJ&#39;, text: &#39;Benin&#39;},
        { id: &#39;BM&#39;, text: &#39;Bermuda&#39;},{ id: &#39;BT&#39;, text: &#39;Bhutan&#39;},
        { id: &#39;BO&#39;, text: &#39;Bolivia&#39;},{ id: &#39;BA&#39;, text: &#39;Bosnia And Herzegovina&#39;},{ id: &#39;BW&#39;, text: &#39;Botswana&#39;},    { id: &#39;BV&#39;, text: &#39;Bouvet Island&#39;},{ id: &#39;BR&#39;, text: &#39;Brazil&#39;},
        { id: &#39;IO&#39;, text: &#39;British Indian Ocean Territory&#39;},{ id: &#39;BN&#39;, text: &#39;Brunei Darussalam&#39;},{ id: &#39;BG&#39;, text: &#39;Bulgaria&#39;},{ id: &#39;BF&#39;, text: &#39;Burkina Faso&#39;},{ id: &#39;BI&#39;, text: &#39;Burundi&#39;},{ id: &#39;KH&#39;, text: &#39;Cambodia&#39;},{ id: &#39;CM&#39;, text: &#39;Cameroon&#39;},{ id: &#39;CA&#39;, text: &#39;Canada&#39;},
        { id: &#39;CV&#39;, text: &#39;Cape Verde&#39;},{ id: &#39;KY&#39;, text: &#39;Cayman Islands&#39;},{ id: &#39;CF&#39;, text: &#39;Central African Republic&#39;},{ id: &#39;TD&#39;, text: &#39;Chad&#39;},{ id: &#39;CL&#39;, text: &#39;Chile&#39;},{ id: &#39;CN&#39;, text: &#39;China&#39;},{ id: &#39;CX&#39;, text: &#39;Christmas Island&#39;},{ id: &#39;CC&#39;, text: &#39;Cocos (Keeling) Islands&#39;},{ id: &#39;CO&#39;, text: &#39;Colombia&#39;},{ id: &#39;KM&#39;, text: &#39;Comoros&#39;},{ id: &#39;CG&#39;, text: &#39;Congo&#39;},{ id: &#39;CD&#39;, text: &#39;Congo, Democratic Republic Of&#39;},{ id: &#39;CK&#39;, text: &#39;Cook Islands&#39;},{ id: &#39;CR&#39;, text: &#39;Costa Rica&#39;},{ id: &#39;CI&#39;, text: &#39;Cote D\&#39;Ivoire&#39;},{ id: &#39;HR&#39;, text: &#39;Croatia&#39;},
        { id: &#39;CU&#39;, text: &#39;Cuba&#39;},{ id: &#39;CY&#39;, text: &#39;Cyprus&#39;},
        { id: &#39;CZ&#39;, text: &#39;Czech Republic&#39;},{ id: &#39;DK&#39;, text: &#39;Denmark&#39;},{ id: &#39;DJ&#39;, text: &#39;Djibouti&#39;},{ id: &#39;DM&#39;, text: &#39;Dominica&#39;},{ id: &#39;DO&#39;, text: &#39;Dominican Republic&#39;},
        { id: &#39;EC&#39;, text: &#39;Ecuador&#39;},{ id: &#39;EG&#39;, text: &#39;Egypt&#39;},
        { id: &#39;SV&#39;, text: &#39;El Salvador&#39;},{ id: &#39;GQ&#39;, text: &#39;Equatorial Guinea&#39;},{ id: &#39;ER&#39;, text: &#39;Eritrea&#39;},
        { id: &#39;EE&#39;, text: &#39;Estonia&#39;},{ id: &#39;ET&#39;, text: &#39;Ethiopia&#39;},{ id: &#39;FK&#39;, text: &#39;Falkland Islands (Malvinas)&#39;},
        { id: &#39;FO&#39;, text: &#39;Faroe Islands&#39;},{ id: &#39;FJ&#39;, text: &#39;Fiji&#39;},{ id: &#39;FI&#39;, text: &#39;Finland&#39;},{ id: &#39;FR&#39;, text: &#39;France&#39;},{ id: &#39;GF&#39;, text: &#39;French Guiana&#39;},{ id: &#39;PF&#39;, text: &#39;French Polynesia&#39;},{ id: &#39;TF&#39;, text: &#39;French Southern Territories&#39;},{ id: &#39;GA&#39;, text: &#39;Gabon&#39;},{ id: &#39;GM&#39;, text: &#39;Gambia&#39;},{ id: &#39;GE&#39;, text: &#39;Georgia&#39;},{ id: &#39;DE&#39;, text: &#39;Germany&#39;},{ id: &#39;GH&#39;, text: &#39;Ghana&#39;},{ id: &#39;GI&#39;, text: &#39;Gibraltar&#39;},{ id: &#39;GR&#39;, text: &#39;Greece&#39;},
        { id: &#39;GL&#39;, text: &#39;Greenland&#39;},{ id: &#39;GD&#39;, text: &#39;Grenada&#39;},{ id: &#39;GP&#39;, text: &#39;Guadeloupe&#39;},{ id: &#39;GU&#39;, text: &#39;Guam&#39;},{ id: &#39;GT&#39;, text: &#39;Guatemala&#39;},{ id: &#39;GG&#39;, text: &#39;Guernsey&#39;},{ id: &#39;GN&#39;, text: &#39;Guinea&#39;},{ id: &#39;GW&#39;, text: &#39;Guinea-Bissau&#39;},{ id: &#39;GY&#39;, text: &#39;Guyana&#39;},
        { id: &#39;HT&#39;, text: &#39;Haiti&#39;},{ id: &#39;HM&#39;, text: &#39;Heard Island &amp; Mcdonald Islands&#39;},{ id: &#39;VA&#39;, text: &#39;Holy See (Vatican City State)&#39;},{ id: &#39;HN&#39;, text: &#39;Honduras&#39;},
        { id: &#39;HK&#39;, text: &#39;Hong Kong&#39;},{ id: &#39;HU&#39;, text: &#39;Hungary&#39;},{ id: &#39;IS&#39;, text: &#39;Iceland&#39;},
        { id: &#39;IN&#39;, text: &#39;India&#39;},{ id: &#39;ID&#39;, text: &#39;Indonesia&#39;},
        { id: &#39;IR&#39;, text: &#39;Iran, Islamic Republic Of&#39;},{ id: &#39;IQ&#39;, text: &#39;Iraq&#39;},{ id: &#39;IE&#39;, text: &#39;Ireland&#39;},{ id: &#39;IM&#39;, text: &#39;Isle Of Man&#39;},{ id: &#39;IL&#39;, text: &#39;Israel&#39;},
        { id: &#39;IT&#39;, text: &#39;Italy&#39;},{ id: &#39;JM&#39;, text: &#39;Jamaica&#39;},
        { id: &#39;JP&#39;, text: &#39;Japan&#39;},{ id: &#39;JE&#39;, text: &#39;Jersey&#39;},
        { id: &#39;JO&#39;, text: &#39;Jordan&#39;},{ id: &#39;KZ&#39;, text: &#39;Kazakhstan&#39;},{ id: &#39;KE&#39;, text: &#39;Kenya&#39;},{ id: &#39;KI&#39;, text: &#39;Kiribati&#39;},{ id: &#39;KR&#39;, text: &#39;Korea&#39;},{ id: &#39;KW&#39;, text: &#39;Kuwait&#39;},{ id: &#39;KG&#39;, text: &#39;Kyrgyzstan&#39;},{ id: &#39;LA&#39;, text: &#39;Lao People\&#39;s Democratic Republic&#39;},{ id: &#39;LV&#39;, text: &#39;Latvia&#39;},{ id: &#39;LB&#39;, text: &#39;Lebanon&#39;},{ id: &#39;LS&#39;, text: &#39;Lesotho&#39;},{ id: &#39;LR&#39;, text: &#39;Liberia&#39;},{ id: &#39;LY&#39;, text: &#39;Libyan Arab Jamahiriya&#39;},{ id: &#39;LI&#39;, text: &#39;Liechtenstein&#39;},{ id: &#39;LT&#39;, text: &#39;Lithuania&#39;},{ id: &#39;LU&#39;, text: &#39;Luxembourg&#39;},{ id: &#39;MO&#39;, text: &#39;Macao&#39;},
        { id: &#39;MK&#39;, text: &#39;Macedonia&#39;},{ id: &#39;MG&#39;, text: &#39;Madagascar&#39;},{ id: &#39;MW&#39;, text: &#39;Malawi&#39;},{ id: &#39;MY&#39;, text: &#39;Malaysia&#39;},{ id: &#39;MV&#39;, text: &#39;Maldives&#39;},
        { id: &#39;ML&#39;, text: &#39;Mali&#39;},{ id: &#39;MT&#39;, text: &#39;Malta&#39;},
        { id: &#39;MH&#39;, text: &#39;Marshall Islands&#39;},{ id: &#39;MQ&#39;, text: &#39;Martinique&#39;},{ id: &#39;MR&#39;, text: &#39;Mauritania&#39;},{ id: &#39;MU&#39;, text: &#39;Mauritius&#39;},{ id: &#39;YT&#39;, text: &#39;Mayotte&#39;},
        { id: &#39;MX&#39;, text: &#39;Mexico&#39;},{ id: &#39;FM&#39;, text: &#39;Micronesia, Federated States Of&#39;},{ id: &#39;MD&#39;, text: &#39;Moldova&#39;},{ id: &#39;MC&#39;, text: &#39;Monaco&#39;},{ id: &#39;MN&#39;, text: &#39;Mongolia&#39;},{ id: &#39;ME&#39;, text: &#39;Montenegro&#39;},{ id: &#39;MS&#39;, text: &#39;Montserrat&#39;},{ id: &#39;MA&#39;, text: &#39;Morocco&#39;},{ id: &#39;MZ&#39;, text: &#39;Mozambique&#39;},{ id: &#39;MM&#39;, text: &#39;Myanmar&#39;},
        { id: &#39;NA&#39;, text: &#39;Namibia&#39;},{ id: &#39;NR&#39;, text: &#39;Nauru&#39;},
        { id: &#39;NP&#39;, text: &#39;Nepal&#39;},{ id: &#39;NL&#39;, text: &#39;Netherlands&#39;},{ id: &#39;AN&#39;, text: &#39;Netherlands Antilles&#39;},
        { id: &#39;NC&#39;, text: &#39;New Caledonia&#39;},{ id: &#39;NZ&#39;, text: &#39;New Zealand&#39;},{ id: &#39;NI&#39;, text: &#39;Nicaragua&#39;},{ id: &#39;NE&#39;, text: &#39;Niger&#39;},{ id: &#39;NG&#39;, text: &#39;Nigeria&#39;},{ id: &#39;NU&#39;, text: &#39;Niue&#39;},{ id: &#39;NF&#39;, text: &#39;Norfolk Island&#39;},{ id: &#39;MP&#39;, text: &#39;Northern Mariana Islands&#39;},{ id: &#39;NO&#39;, text: &#39;Norway&#39;},{ id: &#39;OM&#39;, text: &#39;Oman&#39;},{ id: &#39;PK&#39;, text: &#39;Pakistan&#39;},{ id: &#39;PW&#39;, text: &#39;Palau&#39;},{ id: &#39;PS&#39;, text: &#39;Palestinian Territory, Occupied&#39;},{ id: &#39;PA&#39;, text: &#39;Panama&#39;},{ id: &#39;PG&#39;, text: &#39;Papua New Guinea&#39;},{ id: &#39;PY&#39;, text: &#39;Paraguay&#39;},{ id: &#39;PE&#39;, text: &#39;Peru&#39;},
        { id: &#39;PH&#39;, text: &#39;Philippines&#39;},{ id: &#39;PN&#39;, text: &#39;Pitcairn&#39;},{ id: &#39;PL&#39;, text: &#39;Poland&#39;},{ id: &#39;PT&#39;, text: &#39;Portugal&#39;},{ id: &#39;PR&#39;, text: &#39;Puerto Rico&#39;},{ id: &#39;QA&#39;, text: &#39;Qatar&#39;},{ id: &#39;RE&#39;, text: &#39;Reunion&#39;},
        { id: &#39;RO&#39;, text: &#39;Romania&#39;},{ id: &#39;RU&#39;, text: &#39;Russian Federation&#39;},{ id: &#39;RW&#39;, text: &#39;Rwanda&#39;},{ id: &#39;BL&#39;, text: &#39;Saint Barthelemy&#39;},{ id: &#39;SH&#39;, text: &#39;Saint Helena&#39;},
        { id: &#39;KN&#39;, text: &#39;Saint Kitts And Nevis&#39;},{ id: &#39;LC&#39;, text: &#39;Saint Lucia&#39;},{ id: &#39;MF&#39;, text: &#39;Saint Martin&#39;},
        { id: &#39;PM&#39;, text: &#39;Saint Pierre And Miquelon&#39;},{ id: &#39;VC&#39;, text: &#39;Saint Vincent And Grenadines&#39;},{ id: &#39;WS&#39;, text: &#39;Samoa&#39;},{ id: &#39;SM&#39;, text: &#39;San Marino&#39;},{ id: &#39;ST&#39;, text: &#39;Sao Tome And Principe&#39;},{ id: &#39;SA&#39;, text: &#39;Saudi Arabia&#39;},{ id: &#39;SN&#39;, text: &#39;Senegal&#39;},{ id: &#39;RS&#39;, text: &#39;Serbia&#39;},{ id: &#39;SC&#39;, text: &#39;Seychelles&#39;},{ id: &#39;SL&#39;, text: &#39;Sierra Leone&#39;},{ id: &#39;SG&#39;, text: &#39;Singapore&#39;},{ id: &#39;SK&#39;, text: &#39;Slovakia&#39;},{ id: &#39;SI&#39;, text: &#39;Slovenia&#39;},
        { id: &#39;SB&#39;, text: &#39;Solomon Islands&#39;},{ id: &#39;SO&#39;, text: &#39;Somalia&#39;},{ id: &#39;ZA&#39;, text: &#39;South Africa&#39;},{ id: &#39;GS&#39;, text: &#39;South Georgia And Sandwich Isl.&#39;},{ id: &#39;ES&#39;, text: &#39;Spain&#39;},{ id: &#39;LK&#39;, text: &#39;Sri Lanka&#39;},
        { id: &#39;SD&#39;, text: &#39;Sudan&#39;},{ id: &#39;SR&#39;, text: &#39;Suriname&#39;},
        { id: &#39;SJ&#39;, text: &#39;Svalbard And Jan Mayen&#39;},{ id: &#39;SZ&#39;, text: &#39;Swaziland&#39;},{ id: &#39;SE&#39;, text: &#39;Sweden&#39;},{ id: &#39;CH&#39;, text: &#39;Switzerland&#39;},{ id: &#39;SY&#39;, text: &#39;Syrian Arab Republic&#39;},{ id: &#39;TW&#39;, text: &#39;Taiwan&#39;},{ id: &#39;TJ&#39;, text: &#39;Tajikistan&#39;},{ id: &#39;TZ&#39;, text: &#39;Tanzania&#39;},
        { id: &#39;TH&#39;, text: &#39;Thailand&#39;},{ id: &#39;TL&#39;, text: &#39;Timor-Leste&#39;},{ id: &#39;TG&#39;, text: &#39;Togo&#39;},{ id: &#39;TK&#39;, text: &#39;Tokelau&#39;},{ id: &#39;TO&#39;, text: &#39;Tonga&#39;},{ id: &#39;TT&#39;, text: &#39;Trinidad And Tobago&#39;},{ id: &#39;TN&#39;, text: &#39;Tunisia&#39;},
        { id: &#39;TR&#39;, text: &#39;Turkey&#39;},{ id: &#39;TM&#39;, text: &#39;Turkmenistan&#39;},{ id: &#39;TC&#39;, text: &#39;Turks And Caicos Islands&#39;},{ id: &#39;TV&#39;, text: &#39;Tuvalu&#39;},{ id: &#39;UG&#39;, text: &#39;Uganda&#39;},{ id: &#39;UA&#39;, text: &#39;Ukraine&#39;},{ id: &#39;AE&#39;, text: &#39;United Arab Emirates&#39;},{ id: &#39;GB&#39;, text: &#39;United Kingdom&#39;},{ id: &#39;US&#39;, text: &#39;United States&#39;},{ id: &#39;UM&#39;, text: &#39;United States Outlying Islands&#39;},{ id: &#39;UY&#39;, text: &#39;Uruguay&#39;},{ id: &#39;UZ&#39;, text: &#39;Uzbekistan&#39;},{ id: &#39;VU&#39;, text: &#39;Vanuatu&#39;},{ id: &#39;VE&#39;, text: &#39;Venezuela&#39;},{ id: &#39;VN&#39;, text: &#39;Viet Nam&#39;},{ id: &#39;VG&#39;, text: &#39;Virgin Islands, British&#39;},{ id: &#39;VI&#39;, text: &#39;Virgin Islands, U.S.&#39;},{ id: &#39;WF&#39;, text: &#39;Wallis And Futuna&#39;},{ id: &#39;EH&#39;, text: &#39;Western Sahara&#39;},{ id: &#39;YE&#39;, text: &#39;Yemen&#39;},
        { id: &#39;ZM&#39;, text: &#39;Zambia&#39;},{ id: &#39;ZW&#39;, text: &#39;Zimbabwe&#39;}
    ];
    $(&#39;#countries&#39;).select2({
        placeholder: &#39;-Select Country-&#39;,
        templateResult: formatCountry,
        data: options
    });
    
    function formatCountry(country){
        if (!country.id) {
            return country.text;
        }
        var $country = $(
            &#39;&amp;lt;span class=&quot;flag-icon flag-icon-&#39;+ country.id.toLowerCase() +&#39; flag-icon-squared&quot;&amp;gt;&amp;lt;/span&amp;gt;&#39; + &#39;&amp;lt;span style=&quot;margin-left:10px;&quot;&amp;gt;&#39;+ country.text+&#39;&amp;lt;/span&amp;gt;&#39;
        );
        return $country;
    };
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;In the above script, the &lt;code&gt;select2()&lt;/code&gt; method will simply replace the plain dropdown with a more customizable one. We also have to set the formatting function to the &lt;code&gt;templateResult&lt;/code&gt; option. This will execute the function for each option in the drop down and will add a country flag image to it.&lt;/p&gt;

&lt;p&gt;Run the script and you will see a nice dropdown that shows the country names with their flags. It also includes an amazing search box which will autosuggest the names of countries when you start typing.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;insert country flag images before country names select2&quot; border=&quot;0&quot; data-original-height=&quot;303&quot; data-original-width=&quot;237&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiae17P88SwTL2zr0Pwy998WMpEdoFRVuepu62Ra7UpLRPCclB6qY61npUUUGuBR-GnrcpWvytc9mumf6P6CJMfybMctzbIB86m_PJpUAvWwrqlg2mDeXg0Y9GGtdM4bE__8kK9dDVvZmom/s1600/insert-country-flag-images-before-country-names-select-option.png&quot; title=&quot;Add Flag Images before Country Names in jQuery&quot; /&gt;&lt;/div&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/dynamic-treeview-menu-php-mysql-ajax.html&quot;&gt;Dynamic Treeview with PHP, MySQL and jQuery&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/send-ajax-request-at-regular-interval.html&quot;&gt;How to Fire AJAX Request at Regular Interval&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Likewise, you can &lt;em&gt;add images to the select box using the jquery select2 plugin&lt;/em&gt;. It&#39;s a nifty add-on that gives you more control over the element which you never get with HTML. I hope this tutorial is useful for you. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/03/add-images-to-dropdown-list-jquery.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWnXefNKT1-j_UIyg8H6XnjNvr47Xnmnn1mtVAHJDIQEnNBN6UZz2rH-nZr3-NroJy03yQMEj2g3mkIQJYW6_u8ATO8wev-PU2IPgdtdEe-I4stPAJPNIjy977ueoQD2QZFhQJClOhSTaQ/s72-c/jquery-add-images-to-dropdown-list.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-6079312548836497882</guid><pubDate>Mon, 26 Mar 2018 14:43:00 +0000</pubDate><atom:updated>2018-03-26T20:13:52.168+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Bootstrap</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><category domain="http://www.blogger.com/atom/ns#">MySQL</category><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">Treeview</category><title>Dynamic Treeview Menu using PHP, MySQL and AJAX Example</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;&lt;em&gt;How to Create Dynamic Treeview Menu using PHP, MySQL and AJAX?&lt;/em&gt; Most modern websites use tree view to display the dynamic sidebar menu for easy navigation. In case you don&#39;t know, a Treeview is a hierarchical representation of elements in a tree-like structure. You can go for jquery solution in this context, but I would recommend &#39;Bootstrap Treeview&#39; plug-in if you use the bootstrap framework to build your websites.&lt;/p&gt;

&lt;p&gt;The plug-in uses JSON dataset to create a hierarchical tree structure. I have already discussed the &lt;a href=&quot;http://www.kodingmadesimple.com/2018/02/create-treeview-bootstrap-jquery.html&quot;&gt;creation of static treeview menu using bootstrap treeview&lt;/a&gt;. But you can also generate a dynamic tree where you pull off the data elements stored in the database. In this tutorial I&#39;m going to show you about creating dynamic treeview using php, mysql, ajax and bootstrap.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;bootstrap dynamic treeview example&quot; border=&quot;0&quot; data-original-height=&quot;326&quot; data-original-width=&quot;571&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJey5joCVmxecsL6NLh2aRMU-uu2PqzoCxkkIwDNbpUt_bPov7hgq-TiIwRIz1q3VYjdxzkyWqtxZJHmv9jFqodCj7Si3nEjU-gy9pyy7287nnH9aiQ1-PCCAs7vHjQPfF0CBvLoMlsVGc/s1600/bootstrap-dynamic-treeview-example.png&quot; title=&quot;Dynamic Bootstrap Tree&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;How to Create Dymanic Treeview in PHP &amp; MySQL?&lt;/h2&gt;

&lt;p&gt;For the demo, I&#39;m going to load all the required libraries via CDN. So there&#39;s no need to download them to your web server.&lt;/p&gt;

&lt;p&gt;Here are the simple steps to build a dynamic tree view structure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-1)&lt;/strong&gt; First create the mysql database required for the example. I would suggest you follow the same schema given below to maintain the hierarchy structure.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
CREATE DATABASE `my_demo`;
USE `my_demo`;

CREATE TABLE `tbl_categories` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `item_name` varchar(50) NOT NULL,
  `parent_id` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=18;

INSERT INTO `tbl_categories` (`id`, `item_name`, `parent_id`) VALUES
(1, &#39;Electronics&#39;, 0),
(2, &#39;Televisions&#39;, 1),
(3, &#39;Tube&#39;, 2),
(4, &#39;LCD&#39;, 2),
(5, &#39;Plasma&#39;, 2),
(6, &#39;Computers and Laptops&#39;, 1),
(7, &#39;Desktops&#39;, 6),
(8, &#39;Laptops&#39;, 6),
(9, &#39;Netbooks&#39;, 6),
(10, &#39;Tablets&#39;, 6),
(11, &#39;Android&#39;, 10),
(12, &#39;iPad&#39;, 10),
(13, &#39;Mobile Phones&#39;, 1),
(14, &#39;Basic Cell Phones&#39;, 13),
(15, &#39;Smartphones&#39;, 13),
(16, &#39;Android Phones&#39;, 15),
(17, &#39;iPhone&#39;, 15);
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-2)&lt;/strong&gt; Next create a php script to be executed by ajax call. This will fetch the menu data from the &lt;strong&gt;&#39;tbl_categories&#39;&lt;/strong&gt; table, create hierarchical tree structure and return it as &lt;strong&gt;JSON&lt;/strong&gt; data.&lt;/p&gt;

&lt;h3&gt;fetch_categories.php&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
$db = mysqli_connect(&#39;localhost&#39;, &#39;mysql_username&#39;, &#39;mysql_password&#39;, &#39;my_demo&#39;);
$sql = &#39;select id, item_name as name, item_name as text, parent_id from tbl_categories&#39;;
$result = mysqli_query($db, $sql);

$tree_data = mysqli_fetch_all($result, MYSQLI_ASSOC);

foreach($tree_data as $k =&amp;gt; &amp;$v){
    $tmp_data[$v[&#39;id&#39;]] = &amp;$v;
}

foreach($tree_data as $k =&amp;gt; &amp;$v){
    if($v[&#39;parent_id&#39;] &amp;&amp; isset($tmp_data[$v[&#39;parent_id&#39;]])){
        $tmp_data[$v[&#39;parent_id&#39;]][&#39;nodes&#39;][] = &amp;$v;
    }
}

foreach($tree_data as $k =&amp;gt; &amp;$v){
    if($v[&#39;parent_id&#39;] &amp;&amp; isset($tmp_data[$v[&#39;parent_id&#39;]])){
        unset($tree_data[$k]);
    }
}

echo json_encode($tree_data);
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-3)&lt;/strong&gt; Finally, create an HTML file and add placeholder to show the tree view. Here you have to load all the required libraries such as bootstrap, jquery and bootstrap treeview libraries.&lt;/p&gt;

&lt;h3&gt;index.html&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;title&amp;gt;PHP and MySQl Dynamic Treeview Example&amp;lt;/title&amp;gt;
    &amp;lt;link href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&amp;gt;
    &amp;lt;link href=&quot;https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootstrap-treeview.min.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&amp;gt;
&amp;lt;/head&amp;gt;

&amp;lt;body&amp;gt;
    &amp;lt;div class=&quot;container&quot;&amp;gt;
        &amp;lt;div class=&quot;row&quot;&amp;gt;
            &amp;lt;div class=&quot;col-sm-4&quot;&amp;gt;
            &amp;lt;h3 class=&quot;text-center bg-primary&quot;&amp;gt;Dynamic Treeview Example&amp;lt;/h3&amp;gt;
                &amp;lt;div id=&quot;myTree&quot;&amp;gt;&amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;

            &amp;lt;div class=&quot;col-sm-8&quot;&amp;gt;
                &amp;lt;!-- here goes other page contents --&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script src=&quot;https://code.jquery.com/jquery-2.1.1.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/bootstrap-treeview/1.2.0/bootstrap-treeview.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
    
    &amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    $(document).ready(function(){
        $.ajax({
            url: &#39;fetch_categories.php&#39;,
            method: &#39;GET&#39;,
            dataType: &#39;json&#39;,
            success: function(data){
                $(&#39;#myTree&#39;).treeview({data: data});
            }
        });
    });
    &amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;In the &lt;code&gt;success&lt;/code&gt; function of the &lt;code&gt;ajax()&lt;/code&gt; call, we have invoked the &lt;code&gt;treeview()&lt;/code&gt; method of the &lt;strong&gt;&#39;bootstrap-treeview&#39;&lt;/strong&gt; library to display the tree structure on the corresponding placeholder.&lt;/p&gt;

&lt;p&gt;When you run &#39;index.html&#39; a tree menu similar to this one will appear,&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;ajax dynamic treeview php mysql example&quot; border=&quot;0&quot; data-original-height=&quot;576&quot; data-original-width=&quot;317&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmbCcht2rQaRuJHsVCL6Mtzz19VLZzRLj7KgxFZ6Ix4-30w1jEJpnKEyzRQ9usbyts3EujO5q9vq6sPcSaxba5O3CcHoVHwm3AobPmzVBGgGOreNG6SA_xBjbFxSxZptx5KG8fKrDbNz5U/s1600/ajax-dynamic-treeview-php-mysql-example.png&quot; title=&quot;PHP MySQL Dynamic Treeview Menu&quot; /&gt;&lt;/div&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;
&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/convert-html-to-pdf-php-dompdf.html&quot;&gt;How to Convert HTML to PDF with PHP &amp; DomPDF&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/send-ajax-request-at-regular-interval.html&quot;&gt;How to Send AJAX Request at Regular Interval&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Similarly, you can &lt;strong&gt;create treeview dynamically using php, mysql and ajax&lt;/strong&gt;. You can also add icons, check boxes and filters to the nodes of the tree menu. Check the documentation to learn more about it. I hope this tutorial is useful for you. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/03/dynamic-treeview-menu-php-mysql-ajax.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiJey5joCVmxecsL6NLh2aRMU-uu2PqzoCxkkIwDNbpUt_bPov7hgq-TiIwRIz1q3VYjdxzkyWqtxZJHmv9jFqodCj7Si3nEjU-gy9pyy7287nnH9aiQ1-PCCAs7vHjQPfF0CBvLoMlsVGc/s72-c/bootstrap-dynamic-treeview-example.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-9031012473225158293</guid><pubDate>Mon, 19 Mar 2018 15:15:00 +0000</pubDate><atom:updated>2018-03-19T20:45:25.352+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CodeIgniter</category><category domain="http://www.blogger.com/atom/ns#">DomPDF</category><category domain="http://www.blogger.com/atom/ns#">PDF</category><title>Generate PDF from View using DomPDF in CodeIgniter 3</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi, in this post let&#39;s see &lt;strong&gt;how to generate pdf from view using dompdf in codeigniter 3&lt;/strong&gt;. When it comes to generating reports, the pdf format is the most popular in use. In addition, many websites offer downloadable documents, forms and files in pdf format by converting from html to pdf. There are several add-ons and libraries to aid with the process, such as DOMPDF, MPDF, FPDF, TCPDF, Html2Pdf etc. In this case, I will use the DomPDF library to generate PDF documents in code igniter.&lt;/p&gt;

&lt;p&gt;DomPDF renders the html layout to a PDF file and supports the loading of external style sheets and inline css styles when creating pdf.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;codeigniter generate pdf from view dompdf&quot; border=&quot;0&quot; data-original-height=&quot;324&quot; data-original-width=&quot;569&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyRFNKfI3cFNbuzrZceU0LImAM6skge8IYntqTPuRPRc2YWFzMpbPn7NgcSazYi_7oPSFnOdbOAt3XRLHE47SWu1pra4YCRC3t1S7Fr_M9NwwB6db-J0lRh95Ou3nEHVTMwNV1-cpcCgt3/s1600/codeigniter-generate-pdf-from-view-dompdf.png&quot; title=&quot;CodeIgniter Generate PDF from View&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;How to Generate PDF from CodeIgniter View?&lt;/h2&gt;

&lt;p&gt;Here we are going to see how to generate pdf document from a codeigniter view file. Basically dompdf reads the html content, &lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/convert-html-to-pdf-php-dompdf.html&quot;&gt;create pdf from html&lt;/a&gt; and writes it to the output stream.&lt;/p&gt;

&lt;p&gt;The following are the steps to implement PDF generation in code igniter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-1)&lt;/strong&gt; First &lt;a href=&quot;https://github.com/dompdf/dompdf/releases&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;download dompdf&lt;/a&gt; library, then extract and move the folder to codeigniter&#39;s &#39;application/library&#39; folder.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-2)&lt;/strong&gt; Next create a custom code igniter library to create pdf using the dompdf class. Create the file &#39;pdf.php&#39; inside &#39;application/library&#39; and copy the below contents into the file.&lt;/p&gt;

&lt;h3&gt;Pdf.php&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
defined(&#39;BASEPATH&#39;) OR exit(&#39;No direct script access allowed&#39;);

require_once(dirname(__FILE__) . &#39;/dompdf/autoload.inc.php&#39;);

class Pdf
{
    function createPDF($html, $filename=&#39;&#39;, $download=TRUE, $paper=&#39;A4&#39;, $orientation=&#39;portrait&#39;){
        $dompdf = new Dompdf\DOMPDF();
        $dompdf-&amp;gt;load_html($html);
        $dompdf-&amp;gt;set_paper($paper, $orientation);
        $dompdf-&amp;gt;render();
        if($download)
            $dompdf-&amp;gt;stream($filename.&#39;.pdf&#39;, array(&#39;Attachment&#39; =&amp;gt; 1));
        else
            $dompdf-&amp;gt;stream($filename.&#39;.pdf&#39;, array(&#39;Attachment&#39; =&amp;gt; 0));
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;In the above class, the function &lt;code&gt;createPDF()&lt;/code&gt; converts raw html data into pdf document. It allows you to pass five different parameters to control the way in which the pdf is generated. The first parameter is mandatory and the rest are optional.&lt;/p&gt;

&lt;p&gt;By default, the function will create downloadable pdf. If you want to preview the file before downloading it, you must set $download=FALSE.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;STEP-3)&lt;/strong&gt; Then you need the codeigniter view file. This view contains a simple html table which has to be converted into a pdf document.&lt;/p&gt;

&lt;p&gt;Create &#39;GeneratePdfView.php&#39; inside &#39;application/views&#39; folder and copy the contents below into it.&lt;/p&gt;

&lt;h3&gt;GeneratePdfView.php&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta content=&quot;width=device-width, initial-scale=1.0&quot; name=&quot;viewport&quot;&amp;gt;
    &amp;lt;meta charset=&quot;utf-8&quot;&amp;gt;
    &amp;lt;title&amp;gt;Create PDF from View in CodeIgniter Example&amp;lt;/title&amp;gt;
    &amp;lt;link href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot; /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;h1 class=&quot;text-center bg-info&quot;&amp;gt;Generate PDF from View using DomPDF&amp;lt;/h1&amp;gt;
&amp;lt;table class=&quot;table table-striped table-hover&quot;&amp;gt;
    &amp;lt;thead&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;th&amp;gt;#&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Book Name&amp;lt;/th&amp;gt;
            &amp;lt;th&amp;gt;Author&amp;lt;/th&amp;gt;
        &amp;lt;/tr&amp;gt;
    &amp;lt;/thead&amp;gt;
    &amp;lt;tbody&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;td&amp;gt;1&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;PHP and MySQL for Dynamic Web Sites&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Larry Ullman&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;td&amp;gt;2&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Pro MEAN Stack Development&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Elad Elrom&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;td&amp;gt;3&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Restful API Design&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Matthias Biehl&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;td&amp;gt;4&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Pro PHP MVC&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Chris Pitt&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tr&amp;gt;
            &amp;lt;td&amp;gt;5&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Mastering Spring MVC 4&amp;lt;/td&amp;gt;
            &amp;lt;td&amp;gt;Geoffroy Warin&amp;lt;/td&amp;gt;
        &amp;lt;/tr&amp;gt;
        &amp;lt;tbody&amp;gt;
&amp;lt;/table&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;STEP-4)&lt;/strong&gt; Finally you need a code igniter controller file. Create &#39;GeneratePdfController.php&#39; inside &#39;application/controllers&#39;. In the &lt;code&gt;index()&lt;/code&gt; function, load the &#39;pdf&#39; library and convert the view into a pdf file.&lt;/p&gt;

&lt;h3&gt;GeneratePdfController.php&lt;/h3&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
defined(&#39;BASEPATH&#39;) OR exit(&#39;No direct script access allowed&#39;);

class GeneratePdfController extends CI_Controller {

    function index()
    {
        $this-&amp;gt;load-&amp;gt;library(&#39;pdf&#39;);
        $html = $this-&amp;gt;load-&amp;gt;view(&#39;GeneratePdfView&#39;, [], true);
        $this-&amp;gt;pdf-&amp;gt;createPDF($html, &#39;mypdf&#39;, false);
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;That&#39;s it. We have all the required files in place. Run the controller and you can see the preview of the newly created pdf document on the browser.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;convert html to pdf codeigniter&quot; border=&quot;0&quot; data-original-height=&quot;373&quot; data-original-width=&quot;580&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgks-7buIuk7j-X79ouUJEcGP0Jnga6NFDa8MdHMoJgIJTTok7R-lbEL46B9NqI0VAiknoXp8TdZPyenzJMAi45gnfUfOE5_EQqBzttlEmKCxXhofqSPIck1zcCaMxle5AHJG6o35ug0smy/s1600/convert-html-to-pdf-codeigniter.png&quot; title=&quot;Create PDF using DomPDF&quot; /&gt;&lt;/div&gt;

&lt;p&gt;To simply download the pdf file on load use,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$this-&amp;gt;pdf-&amp;gt;createPDF($html, &#39;mypdf&#39;);
&lt;/pre&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/03/ajax-pagination-codeigniter.html&quot;&gt;Create AJAX Pagination using CodeIgniter and Bootstrap&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/02/codeigniter-autocomplete-search-from-database-ajax.html&quot;&gt;AJAX Autocomplete Search from Database in CodeIgniter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I hope you now understand better the &lt;em&gt;generation of PDF from the codeigniter view&lt;/em&gt;. If you are using composer, just auto load the &#39;./vendor/autoload.php&#39; file and you are good to go from there. Hope you find this tutorial useful. Please share it on your social circle if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/03/codeigniter-generate-pdf-from-view-dompdf.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgyRFNKfI3cFNbuzrZceU0LImAM6skge8IYntqTPuRPRc2YWFzMpbPn7NgcSazYi_7oPSFnOdbOAt3XRLHE47SWu1pra4YCRC3t1S7Fr_M9NwwB6db-J0lRh95Ou3nEHVTMwNV1-cpcCgt3/s72-c/codeigniter-generate-pdf-from-view-dompdf.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-4818940901292249912</guid><pubDate>Thu, 15 Mar 2018 13:49:00 +0000</pubDate><atom:updated>2018-03-15T19:19:04.962+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><title>How to Send AJAX Request at Regular Interval</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;At times, you may want to update part of a web page repeatedly. Let&#39;s say, for example, that you have a website flashing live news or a cricket score update. Here you have to refresh that specific content on a regular basis and ajax is the best way to do it.&lt;/p&gt;

&lt;p&gt;You are left with two options when you want to &lt;strong&gt;fire ajax request at specific time interval&lt;/strong&gt; - one is &lt;/strong&gt;setInterval()&lt;/strong&gt; and the other is &lt;strong&gt;setTimeout()&lt;/strong&gt; function. Both JavaScript functions are good for doing periodic tasks, but one is much better than the other. In this tutorial we will see what is the best approach and how.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;send ajax request at regular interval&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFRMcHK-9V4I-qiDgLUNTsW4J9KRGqyTrFqvqOxFaEb8BFR-wB8aMGBEHUM_HDyNlQEWo215UdY46gSvVeGHcbUXezcab0NVZUR-aJwGTrVOKniVSwOxnSeV8ZVNzdzo43P1ZvPCqIj2_j/s1600/send-ajax-request-at-regular-interval.png&quot; title=&quot;Send AJAX Call Continuously&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;Fire Continuous AJAX Request using setInterval():&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;setInterval()&lt;/code&gt; is the common method used for repeated tasks. It executes a function at specified interval in milliseconds. Repeated calls can only be stopped using the &lt;code&gt;clearInterval()&lt;/code&gt; method or by closing the window.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
setInterval(function, milliseconds);
&lt;/pre&gt;

&lt;p&gt;Consider the following example. This java script will fire ajax call every 5 seconds to the server and update the news feed.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
function getFeed() {
    $.ajax({
        url: &#39;get_news_feed.php&#39;,
        type: &#39;POST&#39;,
        success: function(data) {
            $(&#39;#result&#39;).html(data);
        }
    });
}

$(document).ready(function() {
    setInterval(getFeed, 5000);
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;At first glance, the script may look fine but it&#39;s not. It continuously executes the &lt;code&gt;getFeed()&lt;/code&gt; function regardless of whether the previous ajax request is completed or not.&lt;/p&gt;

&lt;p&gt;Let&#39;s say you are on a slower network, and the first request was not completed, but you start another one. Soon you would end up in a situation where multiple requests are stacked up that consume shared resources and delay each other.&lt;/p&gt;

&lt;p&gt;To avoid this problem, you can use the setTimeout() method that allows you to wait until the last request is completed before sending the next one.&lt;/p&gt;

&lt;h2&gt;Using setTimeout() Method:&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;setTimeout()&lt;/code&gt; calls a function after the specified delay. Unlike the previous method, it executes the function only once. You have to call again to repeat the execution.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
setTimeout(function, milliseconds);
&lt;/pre&gt;

&lt;blockquote&gt;It&#39;s best to use setTimeout() method instead of setInterval() for tasks that take longer than the repetition time interval.&lt;/blockquote&gt;

&lt;p&gt;Below is an example for its usage.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-js codebk&quot;&gt;
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
function getFeed() {
    $.ajax({
        url: &#39;get_news_feed.php&#39;,
        type: &#39;POST&#39;,
        success: function(data) {
            $(&#39;#result&#39;).html(data);
        },
        complete:function(data) {
            setTimeout(getFeed, 5000);
        }
    });
}

$(document).ready(function() {
    setTimeout(getFeed, 5000);
});
&amp;lt;/script&amp;gt;
&lt;/pre&gt;

&lt;p&gt;The above script &lt;a href=&quot;http://www.kodingmadesimple.com/2017/12/ajax-submit-form-without-page-refresh-jquery-php.html&quot;&gt;send ajax request&lt;/a&gt; after waiting for 5 seconds. Upon successful completion, the next one will be fired. Here we have used the &lt;code&gt;complete&lt;/code&gt; callback to verify if the previous request was executed successfully or not.&lt;/p&gt;

&lt;p&gt;As you can see, the second example is much better than the first. It simply waits for the first ajax call to finish before sending the second one. So even if there is a delay for server response, multiple requests won&#39;t be queued.&lt;/p&gt;

&lt;strong&gt;Also Read:&lt;/strong&gt;

&lt;ul&gt;
	&lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2016/12/ajax-login-form-bootstrap-php-oop-mysql-jquery.html&quot;&gt;AJAX Login Form using PHP OOP, MySQL &amp; Bootstrap&lt;/a&gt;&lt;/li&gt;
	&lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2017/01/simple-ajax-pagination-in-jquery-php-pdo-mysql.html&quot;&gt;Simple AJAX Pagination with jQuery, PHP PDO &amp; MySQL&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We have seen &lt;em&gt;two ways to send an ajax call at specific time interval&lt;/em&gt;. And the post also explains why it is better to use setTimeout for repetitive task. I hope this post is useful for you. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/03/send-ajax-request-at-regular-interval.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjFRMcHK-9V4I-qiDgLUNTsW4J9KRGqyTrFqvqOxFaEb8BFR-wB8aMGBEHUM_HDyNlQEWo215UdY46gSvVeGHcbUXezcab0NVZUR-aJwGTrVOKniVSwOxnSeV8ZVNzdzo43P1ZvPCqIj2_j/s72-c/send-ajax-request-at-regular-interval.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-4711413942564693427</guid><pubDate>Mon, 12 Mar 2018 14:13:00 +0000</pubDate><atom:updated>2018-03-12T19:43:49.262+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">DomPDF</category><category domain="http://www.blogger.com/atom/ns#">PDF</category><category domain="http://www.blogger.com/atom/ns#">php</category><title>Convert HTML to PDF in PHP using DomPDF Library</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! In today&#39;s post we will see &lt;strong&gt;how to convert html to pdf in php using dompdf&lt;/strong&gt; library. DomPDF is basically a php library that offers a simple way to convert html content to pdf so that you can generate pdf files on fly with php. Frameworks like Laravel offers separate packages to create pdf files, but there is not so much luck when you work on core php. Hence we need external tools for the task and DomPDF is a good fit for it.&lt;/p&gt;

&lt;p&gt;The library creates downloadable pdf file from the html webpage. It supports CSS2.1 and CSS3 and renders the html layout including the styles. It also handles @import, @media and @screen queries and can load external stylesheets while generating the pdf.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;php convert html to pdf dompdf&quot; border=&quot;0&quot; data-original-height=&quot;324&quot; data-original-width=&quot;569&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdByDDUYpfiQQstF0lhUgxTHOAsVUtQA-URY3QDe7X0LP9Cisfg0tMy7Lbj_KA54s8EEDaejEjTC51mc-Mw6GhahyphenhyphenL595o8wbVPg1ui77uqAClopfOY2_B3E72-zU0EhNOOZbf5TWvB4_H/s1600/php-convert-html-to-pdf-dompdf.png&quot; title=&quot;php convert html to pdf&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;1. Convert HTML to PDF - Basic Usage:&lt;/h2&gt;

&lt;p&gt;Download the dompdf archive &lt;a href=&quot;https://github.com/dompdf/dompdf/releases&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;from here&lt;/a&gt; and extract the contents to your root folder. After that, create a sample php file, &#39;index.php&#39; and include the autoloader file to load the required dompdf libraries and helper functions into your PHP project.&lt;/p&gt;

&lt;p&gt;The following php script describes the basic usage of the dompdf class. It converts simple html content into pdf and output to the browser.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
// include autoloader
require_once &#39;dompdf/autoload.inc.php&#39;;

// import dompdf class into global namespace
use Dompdf\Dompdf;

// instantiate dompdf class
$dompdf = new Dompdf();

// pdf content
$html = &#39;&amp;lt;h1 style=&quot;color:blue;&quot;&amp;gt;Hello World!&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;A PDF generated by DomPDF library.&amp;lt;/p&amp;gt;&#39;;

// load html
$dompdf-&amp;gt;loadHtml($html);

// set paper size and orientation
$dompdf-&amp;gt;setPaper(&#39;A4&#39;, &#39;landscape&#39;);

// render html as pdf
$dompdf-&amp;gt;render();

// output the pdf to browser
$dompdf-&amp;gt;stream();
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;The function &lt;code&gt;setPaper()&lt;/code&gt; is optional. If not provided, the default page settings will be used for rendering the pdf.&lt;/p&gt;

&lt;h2&gt;2. Generate PDF and Show File Preview:&lt;/h2&gt;

&lt;p&gt;The dompdf library offers an option to preview the pdf file before downloading. After generating the pdf, display it on the browser to get a preview using the &lt;code&gt;stream()&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;This method takes two parameters of which the first is the filename and the second is the optional parameter called &lt;code&gt;Attachment&lt;/code&gt;. The default value for this param is &#39;1&#39; forcing the browser to open the download pop-up window. Instead, you must set it as &#39;0&#39; for the browser preview.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
require_once &#39;dompdf/autoload.inc.php&#39;;
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$html = &#39;&amp;lt;h1 style=&quot;color:blue;&quot;&amp;gt;Hello World!&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;A PDF generated by DomPDF library.&amp;lt;/p&amp;gt;&#39;;
$dompdf-&amp;gt;loadHtml($html);
$dompdf-&amp;gt;setPaper(&#39;A4&#39;, &#39;landscape&#39;);
$dompdf-&amp;gt;render();

// preview pdf
$dompdf-&amp;gt;stream(&#39;newfile&#39;,array(&#39;Attachment&#39;=&amp;gt;0));
?&amp;gt;
&lt;/pre&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;generate pdf from html php dompdf&quot; border=&quot;0&quot; data-original-height=&quot;371&quot; data-original-width=&quot;580&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgToFTWCQ45O0yQ_FCYExg6_WHUboHtZmBZEy1cSaXokdjcg1I3_ghnKEtL8I6-zMIaShUYFXbi61lvEbij2aPCxksBzbvgTlCL7CWhD0CZwk21IBZzA-dqh2YQW9VeWT9Qs9qqRNostk8z/s1600/generate-pdf-from-html-php-dompdf.png&quot; title=&quot;Generate PDF in PHP&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;3. Save PDF to File:&lt;/h2&gt;

&lt;p&gt;To save the created pdf as a file on your local disk, you must output the rendered pdf to a variable and write it to a file using the &lt;code&gt;file_put_contents()&lt;/code&gt; method.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
require_once &#39;dompdf/autoload.inc.php&#39;;
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$html = &#39;&amp;lt;h1 style=&quot;color:blue;&quot;&amp;gt;Hello World!&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;A PDF generated by DomPDF library.&amp;lt;/p&amp;gt;&#39;;
$dompdf-&amp;gt;loadHtml($html);
$dompdf-&amp;gt;setPaper(&#39;A4&#39;, &#39;landscape&#39;);
$dompdf-&amp;gt;render();
// write pdf to a file
$pdf = $dompdf-&amp;gt;output();
file_put_contents(&quot;newfile.pdf&quot;, $pdf);
?&amp;gt;
&lt;/pre&gt;

&lt;h2&gt;4. Generate PDF from HTML File:&lt;/h2&gt;

&lt;p&gt;You can also generate pdf from an html file. First you have to read the contents of the file into a variable using &lt;code&gt;file_get_contents()&lt;/code&gt; method and then load it with the &lt;code&gt;loadHtml()&lt;/code&gt; function of the library.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
require_once &#39;dompdf/autoload.inc.php&#39;;
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$html = file_get_contents(&#39;data.html&#39;);
$dompdf-&amp;gt;loadHtml($html);
$dompdf-&amp;gt;setPaper(&#39;A4&#39;, &#39;landscape&#39;);
$dompdf-&amp;gt;render();
$dompdf-&amp;gt;stream(&#39;newfile&#39;, array(&#39;Attachment&#39;=&amp;gt;0));
?&amp;gt;
&lt;/pre&gt;

&lt;h2&gt;5. DomPDF Options:&lt;/h2&gt;

&lt;p&gt;The library offers a range of options for customization. You can set the options at run time like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
use Dompdf\Dompdf;
$dompdf = new Dompdf();
$dompdf-&amp;gt;set_option(&#39;defaultFont&#39;, &#39;Courier&#39;);
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;For the complete list of available options, see the page &lt;a href=&quot;https://github.com/dompdf/dompdf/blob/master/src/Options.php&quot; rel=&quot;nofollow&quot; target=&quot;_blank&quot;&gt;Dompdf Options&lt;/a&gt; on github.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2016/01/php-login-and-registration-script-with-mysql-example.html&quot;&gt;User Login and Registration Module using PHP &amp; MySQL&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/01/paytm-payment-gateway-integration-php.html&quot;&gt;Paytm Payment Gateway Integration in PHP Example&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To &lt;em&gt;generate pdf files in your php project&lt;/em&gt;, you can use the DomPDF library. The support for CSS gives you good control over the looks of the generated pdf. But keep in mind rendering large tables and files will take time. I hope this post is useful to you. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/03/convert-html-to-pdf-php-dompdf.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdByDDUYpfiQQstF0lhUgxTHOAsVUtQA-URY3QDe7X0LP9Cisfg0tMy7Lbj_KA54s8EEDaejEjTC51mc-Mw6GhahyphenhyphenL595o8wbVPg1ui77uqAClopfOY2_B3E72-zU0EhNOOZbf5TWvB4_H/s72-c/php-convert-html-to-pdf-dompdf.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-2200609205882444547</guid><pubDate>Fri, 09 Mar 2018 13:41:00 +0000</pubDate><atom:updated>2018-03-09T19:11:53.966+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">AJAX</category><category domain="http://www.blogger.com/atom/ns#">CodeIgniter</category><category domain="http://www.blogger.com/atom/ns#">jQuery</category><category domain="http://www.blogger.com/atom/ns#">Pagination</category><title>AJAX Pagination in CodeIgniter Tutorial</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! In this post, we will see &lt;strong&gt;how to make ajax pagination in codeigniter using codeigniter pagination library&lt;/strong&gt;. The Pagination class offers feature rich functions to paginate the query results in view. Although the usage of pagination library is well-documented, paginating the results with jquery ajax is somewhat a mystery. The solutions available around the web are too complicated for beginners. Hence I decided to write a tutorial on the topic that is easy enough for anyone to implement codeigniter pagination with ajax.&lt;/p&gt;

&lt;p&gt;For this example, we&#39;ll need two libraries which are &lt;strong&gt;jQuery&lt;/strong&gt; and &lt;strong&gt;Bootstrap&lt;/strong&gt;. The jQuery.js is for making ajax call and bootstrap is for designing the user interface.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;ajax pagination codeigniter tutorial&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoYM3k7lFpEif2VpfXVnmhXo92NV4cZDkHN3VJRl7e_X19U3w7CbSA9Or_biUXVhN0ydvU82RQMwLRdZXHPVBZnY2vwcnuSkuYE5IFQ50LBl_a_QMCHFn5v4kL6vKTVIWa5hC_OzlVUO0f/s1600/ajax-pagination-codeigniter-tutorial.png&quot; title=&quot;AJAX Pagination&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;CodeIgniter AJAX Pagination Example:&lt;/h2&gt;

&lt;p&gt;To create ajax pagination, I&#39;m going to use the default pagination library of the code igniter framework. Simply follow the below steps to implement the same.&lt;/p&gt;

&lt;h3&gt;STEP-1) Create Database&lt;/h3&gt;

&lt;p&gt;First create the required database, table and the records to use in our example. I&#39;m going to use MySQL here. Just run the following sql queries in mysql and it will take care of DB creation.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
CREATE DATABASE `my_demo`;
USE `my_demo`;

CREATE TABLE IF NOT EXISTS `Employees` (
  `EmpID` int(8) NOT NULL AUTO_INCREMENT,
  `EmpName` varchar(50) NOT NULL,
  `DeptName` varchar(30) NOT NULL,
  `Designation` varchar(25) NOT NULL,
  `DOJ` date NOT NULL,
  `Salary` int(10) NOT NULL,
  PRIMARY KEY (`EmpID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

INSERT INTO `Employees` (`EmpID`, `EmpName`, `DeptName`, `Designation`, `DOJ`, `Salary`) VALUES
(1, &#39;Colleen Hurst&#39;, &#39;HQ&#39;, &#39;Regional Director&#39;, &#39;2009-09-15&#39;, 205500),
(2, &#39;Brielle Williamson&#39;, &#39;Software&#39;, &#39;Integration Specialist&#39;, &#39;2012-12-02&#39;, 372000),
(3, &#39;Garrett Winters&#39;, &#39;Finance&#39;, &#39;Accountant&#39;, &#39;2011-07-25&#39;, 170750),
(4, &#39;Caesar Vance&#39;, &#39;Sales&#39;, &#39;Assistant Manager&#39;, &#39;2011-12-12&#39;, 106450),
(5, &#39;Sonya Frost&#39;, &#39;Software&#39;, &#39;Software Engineer&#39;, &#39;2008-12-13&#39;, 133600),
(6, &#39;Herrod Chandler&#39;, &#39;Sales&#39;, &#39;Sales Executive&#39;, &#39;2012-08-06&#39;, 127500),
(7, &#39;Jena Gaines&#39;, &#39;HQ&#39;, &#39;Manager&#39;, &#39;2008-12-19&#39;, 112560),
(8, &#39;Quinn Flynn&#39;, &#39;Software&#39;, &#39;Support Lead&#39;, &#39;2013-03-03&#39;, 342000);
&lt;/pre&gt;

&lt;h3&gt;STEP-2) Create Model&lt;/h3&gt;

&lt;p&gt;Next, create the codeigniter model to handle database requests. Place this file inside &#39;application&#39; &amp;gt; &#39;models&#39; folder. The file contains &lt;code&gt;getEmployees()&lt;/code&gt; function to fetch a portion of employees records from the database using the limit condition.&lt;/p&gt;

&lt;h5&gt;AjaxPaginationModel.php&lt;/h5&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
class AjaxPaginationModel extends CI_Model {
    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    function getEmployees($limit, $start) {
        $query = $this-&amp;gt;db-&amp;gt;get(&#39;Employees&#39;, $limit, $start);
        return $query-&amp;gt;result();
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;h3&gt;STEP-3) Create Controller&lt;/h3&gt;

&lt;p&gt;Next we need a controller file to regulate the interaction between the front-end and the back-end. Create this file inside &#39;application&#39; &amp;gt; &#39;controllers&#39; folder.&lt;/p&gt;

&lt;p&gt;It contains the default &lt;code&gt;index()&lt;/code&gt; function which creates paging links and obtain the employee records from the model function and passes them to the view file.&lt;/p&gt;

&lt;h5&gt;AjaxPaginationController.php&lt;/h5&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
class AjaxPaginationController extends CI_Controller {
    function __construct() {
        parent::__construct();
        $this-&amp;gt;load-&amp;gt;helper(&#39;url&#39;);
        $this-&amp;gt;load-&amp;gt;database();
        $this-&amp;gt;load-&amp;gt;library(&#39;pagination&#39;);
        $this-&amp;gt;load-&amp;gt;model(&#39;AjaxPaginationModel&#39;);
    }

    function index() {
        //pagination settings
        $config[&#39;base_url&#39;] = site_url(&#39;AjaxPaginationController/index&#39;);
        $config[&#39;total_rows&#39;] = $this-&amp;gt;db-&amp;gt;count_all(&#39;Employees&#39;);
        $config[&#39;per_page&#39;] = &#39;5&#39;;
        $config[&#39;uri_segment&#39;] = 3;
        $choice = $config[&#39;total_rows&#39;] / $config[&#39;per_page&#39;];
        $config[&#39;num_links&#39;] = floor($choice);
        $this-&amp;gt;pagination-&amp;gt;initialize($config);

        $data[&#39;page&#39;] = ($this-&amp;gt;uri-&amp;gt;segment(3)) ? $this-&amp;gt;uri-&amp;gt;segment(3) : 0;

        // fetch employees list
        $data[&#39;results&#39;] = $this-&amp;gt;AjaxPaginationModel-&amp;gt;getEmployees($config[&#39;per_page&#39;], $data[&#39;page&#39;]);       
        // create pagination links
        $data[&#39;links&#39;] = $this-&amp;gt;pagination-&amp;gt;create_links();

        if($this-&amp;gt;input-&amp;gt;post(&#39;ajax&#39;)) {
            $this-&amp;gt;load-&amp;gt;view(&#39;Data&#39;, $data);
        } else {
            $this-&amp;gt;load-&amp;gt;view(&#39;AjaxPaginationView&#39;, $data);
        }
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;h3&gt;STEP-4) Create View&lt;/h3&gt;

&lt;p&gt;Finally we need to create the view file. This is the user interface where the results from the database will be displayed in a neatly organized table along with pagination links at the bottom.&lt;/p&gt;

&lt;p&gt;Please note that to keep this tutorial simple, I haven&#39;t styled the pagination links. You can check here to &lt;a href=&quot;http://www.kodingmadesimple.com/2015/04/php-codeigniter-pagination-twitter-bootstrap-styles.html&quot;&gt;apply bootstrap styles to codeigniter pagination links&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The special thing about the view is that we have split it into two files. One is the main view named &#39;AjaxPaginationView.php&#39; and the other &#39;Data.php&#39; that contains the markup to display the ajax data.&lt;/p&gt;

&lt;h5&gt;AjaxPaginationView.php&lt;/h5&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
    &amp;lt;meta charset=&quot;utf-8&quot;&amp;gt;
    &amp;lt;meta content=&quot;width=device-width, initial-scale=1.0&quot; name=&quot;viewport&quot;&amp;gt;
    &amp;lt;title&amp;gt;CodeIgniter Pagination with AJAX Example&amp;lt;/title&amp;gt;
    &amp;lt;link href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css&quot; type=&quot;text/css&quot; rel=&quot;stylesheet&quot; /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
    &amp;lt;div class=&quot;container&quot;&amp;gt;
        &amp;lt;div class=&quot;row&quot;&amp;gt;
            &amp;lt;h3 class=&quot;text-center bg-success&quot;&amp;gt;AJAX Pagination in CodeIgniter&amp;lt;/h3&amp;gt;
            &amp;lt;div id=&quot;ajax_content&quot;&amp;gt;
                &amp;lt;?php $this-&amp;gt;load-&amp;gt;view(&#39;Data&#39;, $results); ?&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;script src=&quot;https://code.jquery.com/jquery-2.1.1.min.js&quot; type=&quot;text/javascript&quot;&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;script type=&quot;text/javascript&quot;&amp;gt;
    $(function() {
        paginate();
        function paginate() {
            $(&#39;#ajax_links a&#39;).click(function() {
                var url = $(this).attr(&#39;href&#39;);
                $.ajax({
                    url: url,
                    type: &#39;POST&#39;,
                    data: &#39;ajax=true&#39;,
                    success: function(data) {
                        $(&#39;#ajax_content&#39;).html(data);
                    }
                });
                return false;
            });
        }
    });
&amp;lt;/script&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;h5&gt;Data.php&lt;/h5&gt;

&lt;pre class=&quot;prettyprint lang-html codebk&quot;&gt;
&amp;lt;table class=&quot;table table-striped table-hover&quot;&amp;gt;
    &amp;lt;thead&amp;gt;
        &amp;lt;tr&amp;gt;
        &amp;lt;th&amp;gt;#&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Emp Name&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Department&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Designation&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Joining Date&amp;lt;/th&amp;gt;
        &amp;lt;th&amp;gt;Salary&amp;lt;/th&amp;gt;
        &amp;lt;/tr&amp;gt;
    &amp;lt;/thead&amp;gt;
    &amp;lt;tbody&amp;gt;
    &amp;lt;?php for ($i = 0; $i &amp;lt; count($results); ++$i) { ?&amp;gt;
    &amp;lt;tr&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;?php echo ($page+$i+1); ?&amp;gt;&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;?php echo $results[$i]-&amp;gt;EmpName; ?&amp;gt;&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;?php echo $results[$i]-&amp;gt;DeptName; ?&amp;gt;&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;?php echo $results[$i]-&amp;gt;Designation; ?&amp;gt;&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;?php echo $results[$i]-&amp;gt;DOJ; ?&amp;gt;&amp;lt;/td&amp;gt;
        &amp;lt;td&amp;gt;&amp;lt;?php echo $results[$i]-&amp;gt;Salary; ?&amp;gt;&amp;lt;/td&amp;gt;
    &amp;lt;/tr&amp;gt;
    &amp;lt;?php } ?&amp;gt;
    &amp;lt;/tbody&amp;gt;
&amp;lt;/table&amp;gt;
&amp;lt;div id=&quot;ajax_links&quot; class=&quot;text-center&quot;&amp;gt;
    &amp;lt;?php echo $links; ?&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;

&lt;p&gt;In the view file, we have included the java script function to make ajax call and update the data received on the view container.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;codeigniter ajax pagination example&quot; border=&quot;0&quot; data-original-height=&quot;305&quot; data-original-width=&quot;586&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhObMZfyA195QvUoSP0RcEFSVQKUklfO5i0ovVjq-ZMkVGoaf-wZvyeGJHz-VwMY2zaqK2HcWzJXbLRIdYrnGaQZDHUdk3oeFdCjSPwQf1UWOVTIs3dknA_G7xlYK4_DApTVECpcWW3Wun_/s1600/codeigniter-ajax-pagination-example.png&quot; title=&quot;CodeIgniter Pagination AJAX&quot; /&gt;&lt;/div&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2015/10/codeigniter-pagination-with-search-query-example-bootstrap.html&quot;&gt;How to Apply Search Filter to CodeIgniter Pagination&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/02/codeigniter-autocomplete-search-from-database-ajax.html&quot;&gt;Autocomplete Search from Database in CodeIgniter &amp; AJAX&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Likewise, you can &lt;em&gt;create ajax pagination in codeigniter using the regular pagination class&lt;/em&gt; itself. You can also try the &#39;Ajax Pagination&#39; library offered in the code igniter site. The entire concept is simple and easy to implement. I hope you find this tutorial useful. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/03/ajax-pagination-codeigniter.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhoYM3k7lFpEif2VpfXVnmhXo92NV4cZDkHN3VJRl7e_X19U3w7CbSA9Or_biUXVhN0ydvU82RQMwLRdZXHPVBZnY2vwcnuSkuYE5IFQ50LBl_a_QMCHFn5v4kL6vKTVIWa5hC_OzlVUO0f/s72-c/ajax-pagination-codeigniter-tutorial.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-2118928456007336093</guid><pubDate>Mon, 05 Mar 2018 14:30:00 +0000</pubDate><atom:updated>2018-03-05T20:00:59.475+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><category domain="http://www.blogger.com/atom/ns#">PHPMailer</category><category domain="http://www.blogger.com/atom/ns#">Send Email</category><category domain="http://www.blogger.com/atom/ns#">SMTP</category><title>PHP - Send Email via SMTP Server using PHPMailer</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! In this post, let&#39;s see &lt;strong&gt;how to use PHPMailer to send email from PHP&lt;/strong&gt;. PHPMailer is an amazing php library to send emails quickly. We all know the generic PHP&#39;s mail() function helps you send emails. But on the downside, it requires local mail server to send them. And also the setup and configuration is not that easy. But that&#39;s not the case with PHPMailer. The library supports SMTP protocol and allows easy authentication over SSL and TSL. It allows you to display error messages in more than 40 languages in case there is an error when sending emails.&lt;/p&gt;

&lt;p&gt;PHPMailer uses the real &lt;a href=&quot;http://www.kodingmadesimple.com/2016/06/how-to-validate-email-address-in-php.html&quot;&gt;valid email address&lt;/a&gt; to send mails. Hence you have to setup one if you don&#39;t have it. Here, let&#39;s see how to use Gmail SMTP to send email via PHPMailer.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;php send email through smtp using phpmailer&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEgLIKZxVug89gwaaRKH5fq6jyAHnCq-lD5uO8zhIqgQIT7u6pm0lomjQDgIwV7l9spiL5mRrPM6c4OF9l65TrM6RhJ54vvDqh24Ds5WOjCeBqe63iL6N7nTB7okd7NO4c9syuqMoLyyuM/s1600/php-send-email-smtp-phpmailer.png&quot; title=&quot;PHPMailer Send Email&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;Sending Email via Gmail SMTP using PHPMailer:&lt;/h2&gt;

&lt;p&gt;SMTP is basically a mail protocol that sends a request to the mail server and after verification sends it to the mail server of the recipient.&lt;/p&gt;

&lt;p&gt;To send an email via smtp, you need the authentication from the other host. So if you want to use gmail, you must provide the following details for authentication.&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;Host - gmail smtp server&lt;/li&gt;
 &lt;li&gt;Port - smtp port number&lt;/li&gt;
 &lt;li&gt;Username - gmail address&lt;/li&gt;
 &lt;li&gt;Password - gmail a/c password&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;First you need to &lt;a href=&quot;https://github.com/PHPMailer/PHPMailer&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;download&lt;/a&gt; and extract the &#39;PHPMailer&#39; folder to your application root. If you use composer (which is recommended), simply including the &#39;vendor/autoload.php&#39; file in your php script will do. Otherwise, you must load all the required class files manually as I do in the following example.&lt;/p&gt;

&lt;h4&gt;PHPMailer Script to Send Mail:&lt;/h4&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require &#39;PHPMailer/src/Exception.php&#39;;
require &#39;PHPMailer/src/PHPMailer.php&#39;;
require &#39;PHPMailer/src/SMTP.php&#39;;

$mail = new PHPMailer;

// smtp settings
$mail-&amp;gt;isSMTP();
$mail-&amp;gt;SMTPDebug = 2;
$mail-&amp;gt;SMTPAuth = true;
$mail-&amp;gt;Host = &#39;smtp.gmail.com&#39;;
$mail-&amp;gt;Port = 587;
$mail-&amp;gt;SMTPSecure = &#39;tsl&#39;;
$mail-&amp;gt;Username = &#39;myemailaddress@gmail.com&#39;; // change this to yours
$mail-&amp;gt;Password = &#39;********&#39;; // change this to yours

// set from &amp; to email address
$mail-&amp;gt;setFrom(&#39;myemailaddress@gmail.com&#39;, &#39;KMS&#39;); // change this to yours
$mail-&amp;gt;addReplyTo(&#39;myemailaddress@gmail.com&#39;, &#39;KMS&#39;); // change this to yours
$mail-&amp;gt;addAddress(&#39;john.doe@gmail.com&#39;);

// mail content
$mail-&amp;gt;isHTML(true);
$mail-&amp;gt;Subject = &#39;This is the subject&#39;;
$mail-&amp;gt;Body = &#39;&amp;lt;h1&amp;gt;Test Mail!&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;This is the body of the message.&amp;lt;/p&amp;gt;&#39;;

// send email
if($mail-&amp;gt;send()){
    echo &#39;Message has been sent successfully!&#39;;
} else {
    echo &#39;Message could not be sent. Mailer Error: &#39; . $mail-&amp;gt;ErrorInfo;
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;This &lt;a href=&quot;http://www.kodingmadesimple.com/2016/01/send-html-email-in-php-via-smtp.html&quot;&gt;php script send a simple html email&lt;/a&gt; to the recipient&#39;s email address. Note that we have used &lt;code&gt;isHTML(true)&lt;/code&gt; to set the mail format to html.&lt;/p&gt;

&lt;p&gt;The first two lines of the script are used to import PHPMailer classes into the global namespace. Make sure they remain at the very top of your script and not within a function.&lt;/p&gt;

&lt;h3&gt;Sending Mail to Mulitiple Email-IDs:&lt;/h3&gt;

&lt;p&gt;To send an email to multiple email addresses, add the recipients one by one with the &lt;code&gt;addAddress()&lt;/code&gt; function.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$mail-&amp;gt;addAddress(&#39;user1@example.com&#39;, &#39;user 1&#39;);
$mail-&amp;gt;addAddress(&#39;user2@example.com&#39;, &#39;user 2&#39;);
$mail-&amp;gt;addAddress(&#39;user3@example.com&#39;, &#39;user 3&#39;);
&lt;/pre&gt;

&lt;h3&gt;Including CC and BCC:&lt;/h3&gt;

&lt;p&gt;To send &#39;CC&#39; and &#39;BCC&#39;, use &lt;code&gt;addCC()&lt;/code&gt; and &lt;code&gt;addBCC()&lt;/code&gt; functions.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$mail-&amp;gt;addCC(&#39;cc_address@example.com&#39;);
$mail-&amp;gt;addBCC(&#39;bcc_address@example.com&#39;);
&lt;/pre&gt;

&lt;h3&gt;Sending Mail with Attachments:&lt;/h3&gt;

&lt;p&gt;Use the &lt;code&gt;addAttachment()&lt;/code&gt; function to add attachments to the mails.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
// attachment
$mail-&amp;gt;addAttachment(&#39;files/file1.tar.gz&#39;);

// add optional name to the attachment file
$mail-&amp;gt;addAttachment(&#39;images/image1.png&#39;, &#39;newimage.png&#39;);
&lt;/pre&gt;

&lt;p&gt;Some may face problems while sending emails with gmail smtp. This is due to Google blocking the authentication from apps.&lt;/p&gt;

&lt;blockquote&gt;Just log in to your Google account, go to &lt;strong&gt;&#39;Sign-in &amp; security&#39;&lt;/strong&gt; &amp;gt; &lt;strong&gt;&#39;Connected apps &amp; sites&#39;&lt;/strong&gt; and turn on &lt;strong&gt;&#39;Allow less secure apps&#39;&lt;/strong&gt; option.&lt;/blockquote&gt;

&lt;p&gt;You may also face problem if you have enabled two-step verification on your account. Either disable the feature or create a unique password for signing in through apps.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2015/02/twitter-bootstrap-contact-form-php-tutorial-validations.html&quot;&gt;Simple Contact Form to Send Email with PHP &amp; Bootstrap&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2015/02/autocomplete-textbox-from-database-php-jquery.html&quot;&gt;How to Auto Complete Textbox in PHP, MySQL and jQuery&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Following the above procedure, you can easily &lt;em&gt;send emails through smtp with the phpmailer class&lt;/em&gt;. The same applies to any other third-party mail servers. You have to change the smtp host, username and password accordingly. I hope you find this post useful. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/03/php-send-email-smtp-phpmailer.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjEgLIKZxVug89gwaaRKH5fq6jyAHnCq-lD5uO8zhIqgQIT7u6pm0lomjQDgIwV7l9spiL5mRrPM6c4OF9l65TrM6RhJ54vvDqh24Ds5WOjCeBqe63iL6N7nTB7okd7NO4c9syuqMoLyyuM/s72-c/php-send-email-smtp-phpmailer.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-963231699005677884</guid><pubDate>Mon, 05 Mar 2018 06:30:00 +0000</pubDate><atom:updated>2018-03-06T03:52:45.558+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">Laptops</category><category domain="http://www.blogger.com/atom/ns#">Reviews</category><category domain="http://www.blogger.com/atom/ns#">Writing Laptops</category><title>10 Best Laptops for Writers &amp; Writing 2018</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Are you looking for the &lt;em&gt;best laptop for writers?&lt;/em&gt; Then here&#39;s our review for &lt;strong&gt;Top 10 Best Laptops for Writers and Writing 2018&lt;/strong&gt;.  No matter if you are a professional writer, seasonal or a novice there&#39;s a laptop for everyone&#39;s budget here.  The laptops we have recommended are for people who use them mainly for writing purpose and made sure they got spacious backlit keyboard, eye friendly display, no overheating issues and light weight but sturdy chassis.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;top-10-laptops-for-writers-writing&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxdrFJ_vG4XEE4vN98V2qxIIZm3YJeZqGU5CyWlwedNhSHdpOkFNgm7i9-0GHJ5tXEh_SnmP0MChcZXQfs7i0DpPAXkhRl5quzG3lcsyLFpzkGnpU5VfeiJsq7bX8ZxUDQFmYX_VR2Xm_6/s1600/top-10-laptops-for-writers-writing.jpg&quot; title=&quot;Top 10 Best Laptops for Writing&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;&lt;u&gt;Best Writers Laptop Configuration:&lt;/u&gt;&lt;/h2&gt;

&lt;p&gt;Are there any special laptops made for writing? Well! No.  But a laptop specifically used for writing must have certain features that would make a writer&#39;s life easier.  Here we go.&lt;/p&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;strong&gt;Keyboard:&lt;/strong&gt; Backlit Keyboard (to write in low-light conditions) with spacious palm rest.&lt;/li&gt;
 &lt;li&gt;&lt;strong&gt;Storage:&lt;/strong&gt; At least 128GB SSD (SSD is faster and produce less heat.  A must for professional writers who writes all day long)&lt;/li&gt;
 &lt;li&gt;&lt;strong&gt;RAM:&lt;/strong&gt; 6 to 8GB RAM&lt;/li&gt;
 &lt;li&gt;&lt;strong&gt;Processor:&lt;/strong&gt; Good Quad core processor like Intel i3&lt;/li&gt;
 &lt;li&gt;&lt;strong&gt;Portable:&lt;/strong&gt; Light-weight chassis recommended if writers travel a lot.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;&lt;u&gt;Top 10 Best Laptops for Writers &amp; Writing 2018:&lt;/u&gt;&lt;/h2&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;#best-laptop&quot;&gt;The Best Laptop for Writers 2018&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#best-affordable-laptop&quot;&gt;Best Affordable Laptop for Writers&lt;/a&gt; * Editor&#39;s Pick&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#best-cheap-laptop&quot;&gt;Best Cheap Laptop for Writers 2018&lt;/a&gt; * Editor&#39;s Pick&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#laptop-for-professionals&quot;&gt;Best Laptop for Professional Writers&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#best-dell-laptop&quot;&gt;Best Dell Laptop for Writers&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#laptop-for-serious writers&quot;&gt;Best Laptop for Serious Writers&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#best-chromebook&quot;&gt;Best Chromebook for Writers 2018&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#2-in-1-laptop&quot;&gt;Best 2 in 1 Laptop for Writers&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;#laptop-with-backlit-keyboard&quot;&gt;Best Writers Laptop with Backlit Keyboard&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;span id=&quot;best-laptop&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;The Best Laptop for Writers in 2018&lt;/h3&gt;

&lt;h2&gt;1. ASUS ZenBook UX303UA&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B014VHW24Y/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B014VHW24Y&amp;linkId=5de0a6ca87705fabb647a50dda29e93e&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;best-laptop-for-writing-ZenBook-UX303UA&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmkKRQDpAmjqt0qLaoktfYQKHdlM0vlBn65HCzqbS8FAA16db2ErYWXRvRBezbdzNkPDpuxYwzSkxDM3ZY9Z0YBKDzhj9ehR-UPzB19aSbaEpKgCJJEEyBeQGEjedZJ7n1BxIJjPDbEf3M/s1600/best-laptop-for-writing-ZenBook-UX303UA.jpg&quot; title=&quot;Asus ZenBook UX303UA&quot; /&gt;&lt;/div&gt;

&lt;p&gt;ASUS ZenBook UX303UA is our top pick in &lt;strong&gt;Top 10 Laptops for Writers&lt;/strong&gt; sporting the right combination of power, elegance &amp; portability.  Priced under $800, the ultrabook comes with high-end hardware&#39;s and boots and loads documents with lightning speed and suffers no heating problem.&lt;/p&gt;

&lt;p&gt;The laptop comes preinstalled with Windows 10 and sports Intel i5 processor coupled with 8GB RAM, abundant 256GB SSD storage &amp; wide spaced keypad.  Plus the high definition 13.3 inch screen makes it highly portable.  Given the fact it weighs just 3 pounds you can stash it in your backpack and take it on go.&lt;/p&gt;

&lt;p&gt;Besides its 7 hours of battery backup is another huge plus.  There is no overheating with zenbook as it uses SSD for storage which is relatively fast and prone to less heat.  Overall it&#39;s a great investment for serious writers who write for living.&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B014VHW24Y/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B014VHW24Y&amp;linkId=5de0a6ca87705fabb647a50dda29e93e&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;&lt;br/&gt;
&lt;span id=&quot;best-affordable-laptop&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Best Affordable Laptop for Writers under $600&lt;/h3&gt;

&lt;h2&gt;2. Acer Aspire E15&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B01DT4A2R4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B01DT4A2R4&amp;linkId=6c090a5bfd0892ba40f958d2400bcb36&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;best-laptop-for-writers-Aspire-E-15&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZa6GG1FljpEGRTeP5oRPw6mGpDMcnkvi0Pv9VqzEFutKv3wzEV7Qg6SH_Q5TE9zXHw4_GPP1yudcg3BuTkEHN2t4hDzDX1Ayx7u5EUKz-PNyhLYyAsBa6_e_NbNWYGrI1FIh5FHzY4oi2/s1600/best-laptop-for-writers-Aspire-E-15.jpg&quot; title=&quot;Acer Aspire E 15&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Acer Aspire E15 is the best cheap laptop for writers in 2018 with wide 15.6 inch Full HD screen and full-sized keyboard along with comfortable palm rest.  In fact it is one of the &lt;em&gt;best laptop keyboard for writers&lt;/em&gt;.  It includes abundant SSD storage of 256GB GB to store all your writings and features latest Intel Core i5 processor, 8GB RAM, great battery backup and of all windows 10 OS.&lt;/p&gt;

&lt;p&gt;If you are a novoice or a seasonal writer then there&#39;s no point in spending $1000 for a laptop.  A decent mid-range device will do.  At the price tag of just $550, Acer Aspire E15 is the perfect laptop for writers on budget.&lt;/p&gt;

&lt;p&gt;It sports a good NVIDIA GPU so you can use it for gaming if you don&#39;t feel like writing all day.  Another good reason to go for this gem:)&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B01DT4A2R4/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B01DT4A2R4&amp;linkId=6c090a5bfd0892ba40f958d2400bcb36&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;&lt;br/&gt;
&lt;span id=&quot;best-cheap-laptop&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Best Cheap Laptop for Writers 2018&lt;/h3&gt;

&lt;h2&gt;3. HP 15-AY011NR&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B01CGGOZOM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B01CGGOZOM&amp;linkId=1057b02fc2811ba8bef80e370f02a675&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;cheapest-laptop-for-writers-HP-15-ay011nr&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2uIGagkjloRsN1xQJCL3XeJKv52w3-IRjs8IQtUPYm9U9gVRyjPgYEuRD5uXWfWFK2IqtbcW63sCtEYQbFz0VxxrpFW_QbJdyHc04FT-eqKq4Hgce9kDsAouJxh5RMIL_aFOC-8AJY4xK/s1600/cheapest-laptop-for-writers-HP-15-ay011nr.jpg&quot; title=&quot;HP 15 ay011nr&quot; /&gt;&lt;/div&gt;

&lt;p&gt;HP 15-AY011NR is another good writing laptop you can get for $450.  Probably this is the &lt;strong&gt;most affordable laptop with good specs tailored for a writer&#39;s needs&lt;/strong&gt;.  For such a budget device HP 15-AY011NR includes great hardware like 8GB RAM, Core i5 Processor and surprisingly 1TB of hard disk space.&lt;/p&gt;

&lt;p&gt;It offers 15.6 inch wide FHD display and spaciously arranged keyboard with large palm rest area and comes pre-installed with Windows 10 OS to let you start work immediately after purchase.&lt;/p&gt;

&lt;p&gt;The laptop has excellent battery life of seven hours and suitable for outdoor writing.  Highly recommended for beginners &amp; seasonal writers.&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B01CGGOZOM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B01CGGOZOM&amp;linkId=1057b02fc2811ba8bef80e370f02a675&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;&lt;br/&gt;
&lt;span id=&quot;laptop-for-professionals&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Best Laptop for Professional Writers&lt;/h3&gt;

&lt;h2&gt;4. MacBook Pro ME865LL/A&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B0096VBXQE/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B0096VBXQE&amp;linkId=ba7d14f102dfb58c9757eeefdcb084d6&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;best-laptop-for-professional-writers-macbook-pro&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjM1TTSNaI0LEysAbh4AyP1PTXQ9nCxxA11c2ENOZiDAlCzseIPMultt0ZuR_4xVG_T8E_schdcTVK8A6_q7NpSqgv9AjMAmQ65LVI91g98XlNeQ8xuHNnBv5j-_6zmFKwa-HSyK6jgkrj7/s1600/best-laptop-for-professional-writers-macbook-pro.jpg&quot; title=&quot;MacBook Pro&quot; /&gt;&lt;/div&gt;

&lt;p&gt;MacBook Pro with Retina Display is the Perfect Laptop for Professional Writers.  Writers who are used to sit and write for hours starring at the laptop screen might suffer from eye irritation, red or puffy eyes.  Having a laptop like &lt;strong&gt;MacBook with Retina display will keep away eye strain.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Plus the device is highly portable being very thin and light-weight and fits in your smallest backpack easily.  It comes with high-end features like 8GB RAM, 128GB storage space, 13.3 inch screen with retina display and very long battery life.  Plus the keypad has comfortable palm rest space and backlit keys to let you write in low-light conditions.&lt;/p&gt;

&lt;p&gt;Overheating is never an issue with MacBook.  A high-end product recommended for serious writers.&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B0096VBXQE/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B0096VBXQE&amp;linkId=ba7d14f102dfb58c9757eeefdcb084d6&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;&lt;br/&gt;
&lt;span id=&quot;best-dell-laptop&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Best Dell Laptop for Writers&lt;/h3&gt;

&lt;h2&gt;5. Dell Inspiron&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B015PYZ0J6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B015PYZ0J6&amp;linkId=8b47898e8486e975f5c2d9adbf9ab59b&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;top-laptop-for-writers-dell-inspiron&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzURRamqStIAYorFIVDNcp9k8HpbztlW9urTGXXD2ACDlNDsvkDTReT9MSaNbUrRwR9R-vWPkBZeQ0BDCjlse0M0q2C-wmQfrHMQjTx_XsiUY0mYIg9kfDZvjPeQ7ndYrxvCgCJ5vE1XrJ/s1600/top-laptop-for-writers-dell-inspiron.jpg&quot; title=&quot;Dell Inspiron&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Dell Inspiron is another great laptop for professional writers.  Professional writers do need a sturdy &lt;a href=&quot;http://www.kodingmadesimple.com/&quot;&gt;laptop&lt;/a&gt; with wide-screen, full-sized backlit keyboard to write on low-light conditions, ample storage space and good hardware.  Dell Inspiron meets up with all these challenges without trouble and would be a great buy under $1000.&lt;/p&gt;

&lt;p&gt;Provided the specs are latest with Windows 10 OS, powerful Intel i7 processor along with 8GB RAM, Touch-enabled 15.6 inch FHD Screen,  abundant 1TB storage and backlit full-sized keyboard with comfortable palm area.  The laptop is worth every penny you spend and has an excellent battery life of more than seven hours.  Overall Dell Inspiron would be very good companion in your writing career.&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B015PYZ0J6/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B015PYZ0J6&amp;linkId=8b47898e8486e975f5c2d9adbf9ab59b&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;&lt;br/&gt;
&lt;span id=&quot;laptop-for-serious writers&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Best Laptop for Serious Writers&lt;/h3&gt;

&lt;h2&gt;6. Microsoft Surface Book&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B0163GS05Q/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B0163GS05Q&amp;linkId=4ca8233cb0e85b509cc5b67feab1bd9f&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;top-writers-laptop-for-professionals-Surface-Book&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_8EhMGdx1IRrAdHIb0s8jcGgWkmP3zxHcxxvKrWnZ_S4UIElL01sIvMVIPvlrt7q8f_pif8i53kyb4rZMJHsBcKwPAvV6VR9s6C1hD80mVWGbVsRfQtVeJxBInv2YFRVUOYatE0M3L9hG/s1600/top-writers-laptop-for-professionals-Surface-Book.jpg&quot; title=&quot;Microsoft Surface Book&quot; /&gt;&lt;/div&gt;

&lt;p&gt;An expensive high-end laptop from Microsoft and extremely powerful with stunning 12 hours of battery backup, high definition display and comfortable backlit keyboard to write on dim light conditions.  Writing is joy with Surface Book and if you are a professional writer who writes for living, this would be the best investment you make for your career.&lt;/p&gt;

&lt;p&gt;The product comes in six different versions and for full-time writers we would recommend a hardware combination of Intel i5 processor, 8GB RAM, 256GB SSD Storage.  Videos &amp; games are highly enjoyable in Surface Book&#39;s high definition screen.  So if you are fed up with writing all day you can treat yourself for some entertainment.  Highly recommended for professional writers.&lt;/p&gt;
&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B0163GS05Q/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B0163GS05Q&amp;linkId=4ca8233cb0e85b509cc5b67feab1bd9f&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;&lt;br/&gt;
&lt;span id=&quot;best-chromebook&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Best Chromebook for Writers 2018&lt;/h3&gt;

&lt;h2&gt;7. HP Chrome 14&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B0178J9S6C/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B0178J9S6C&amp;linkId=6367dd6ab18682bb6b728598fe1ddb8e&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;best-affordable-laptop-for-journalist-HP-Chrome-14&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi0TMnseyerIpQkttNeXW01soy2gnKXUIvehyphenhyphen1y4k8nmXRU0quMIV6DH0P_OV1iPZDH9jZskpv0-B9KwywyyNAorUmMdjNRMLBJhmMbcOHP6YDc9oH5xmfq2Twkd-K5bTND-LV37UHtgR1K/s1600/best-affordable-laptop-for-journalist-HP-Chrome-14.jpg&quot; title=&quot;HP Chrome 14&quot; /&gt;&lt;/div&gt;

&lt;p&gt;At 3.4 lbs HP Chrome 14 is a great laptop for writers on go and journalists on budget.  It costs you less than $300 and has remarkable battery backup of 8 hours in one go.  Plus access to Google apps and the ability to connect with various Wi-Fi hot spots are other great additions helpful for people who work as team and share information with other members of the team.&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B0178J9S6C/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B0178J9S6C&amp;linkId=6367dd6ab18682bb6b728598fe1ddb8e&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;
&lt;/p&gt;

&lt;h2&gt;8. Samsung Chromebook 2&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B00NJGRLUY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B00NJGRLUY&amp;linkId=a0433522810fd64d939e07024999d87b&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;best-budget-laptop-for-writing-Chromebook-2&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8qAMe9edNKP_LeETxOQ-hj5ul_0DiB8WQB5xxMnlOijS6DTUjB8r2tgCxJl8Gc9hE-QIzor9VC71rr6QeqCteLujI5mPegdkCyg6gKo-8J5tDUm7OazXsmnUm6-uq4GEzNiUtfayzrwU2/s1600/best-budget-laptop-for-writing-Chromebook-2.jpg&quot; title=&quot;Samsung Chromebook 2&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Slim and Light-weight this Chromebook from Samsung runs on Chrome operating system and comes with very useful software packs.  The software&#39;s like AirDroid Premium, Little Bridge &amp; Wunderlist Pro helps you to manage all your android devices on the web and let you synchronize &amp; transfer files with others on your team.  The ergonomic well-spaced keyboard allows you to type fast.  Given the fact there is no hard-disk you have to rely on cloud storages.&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B00NJGRLUY/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B00NJGRLUY&amp;linkId=a0433522810fd64d939e07024999d87b&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;&lt;br/&gt;
&lt;span id=&quot;2-in-1-laptop&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Best 2 in 1 Laptop for Writers&lt;/h3&gt;

&lt;h2&gt;9. HP Pavilion 13 2-in-1 Laptop&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B014X4UAUI/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B014X4UAUI&amp;linkId=f242693eab024a8a5738102ec89ee57d&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;best-portable-laptop-for-writers-HP-Pavilion-13&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiE4yNUXmg-OolLehsHWjJ-d1hUe5-4nMYLhZgkMWSMrlb0fwyiVWLnX-lfrjoesUzd49OLiBlw6IXUjYXkX09-5uGePL70xFVgZLTUu7So91a4JCTOEqaXRRDMWe2OPn_sPQQASjVVMWjs/s1600/best-portable-laptop-for-writers-HP-Pavilion-13.jpg&quot; title=&quot;HP Pavilion 13&quot; /&gt;&lt;/div&gt;

&lt;p&gt;HP Pavilion 13 is a touch-enabled hybrid laptop that duals as a Laptop &amp; Tablet and a perfect fit for Journalists and Writers.  It is highly portable with 13.3 inch high definition touch screen yet has spaciously formed keypad with comfortable palm rest and would be a great choice for writing.&lt;/p&gt;

&lt;p&gt;It comes with windows 10 OS and powered with Intel i3 processor coupled with 8 GB RAM, 126GB SSD disk and 7 hours of battery backup.  It makes for a great companion on your travel and can be bought for under $600.&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B014X4UAUI/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B014X4UAUI&amp;linkId=f242693eab024a8a5738102ec89ee57d&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;&lt;br/&gt;
&lt;span id=&quot;laptop-with-backlit-keyboard&quot;&gt;&lt;/span&gt;&lt;/p&gt;

&lt;h3&gt;Best Writers Laptop with Backlit Keyboard&lt;/h3&gt;

&lt;h2&gt;10. Lenovo Yoga 3 Pro&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B00OVFGU36/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B00OVFGU36&amp;linkId=c0e9a96492f765ba789d7e20d62f5f58&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;kms-red-link&quot;&gt;Check Price @ Amazon&lt;/a&gt;&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;light-weight-laptop-for-writers-yoga-3-pro&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVb5BQoKYlfDM99dVMG-JzcrnNVHzkTelHxvA_0-6LA2Xqxdrqx6YVQFF27Yc9c3eLP-ZbA0S-NTnNQKjViqYK9inXeuVxWyrPA2NhfBe5RyWkN3p5ojyE907Zs3Mzz5C4WKE4GHysxbXE/s1600/light-weight-laptop-for-writers-yoga-3-pro.png&quot; title=&quot;Lenovo Yoga 3 Pro&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Yoga 3 pro is another good mid-range laptop for writers from Lenovo brand.  The laptop runs on windows 10 operating system and comfortable for writing with well-spaced backlit keyboard and 13.3-inch QHD glossy multi-touch display.&lt;/p&gt;

&lt;p&gt;It packs powerful Intel Core Processor, 8GB RAM, and huge 256GB SSD to store all your files.  With 13.3 inch it&#39;s very portable and if you like to write on outdoors then it easily sustains for up to 9 hours without power.  There is no doubt Yoga 3 Pro comes with all good features a writer needs in a laptop and would be another great choice for writing.&lt;/p&gt;

&lt;p style=&quot;padding: 20px 0;&quot;&gt;
&lt;a href=&quot;https://www.amazon.com/gp/product/B00OVFGU36/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=kodingmades0d-20&amp;camp=1789&amp;creative=9325&amp;linkCode=as2&amp;creativeASIN=B00OVFGU36&amp;linkId=c0e9a96492f765ba789d7e20d62f5f58&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot; class=&quot;red-button&quot;&gt;Get It Now From Amazon &amp;raquo;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Related:&lt;/strong&gt; &lt;a href=&quot;http://www.kodingmadesimple.com/2016/11/top-10-best-laptops-for-programming-coding-developers.html&quot;&gt;Best Laptops for Programming &amp; Coding 2018&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;Over To You:&lt;/h2&gt;

&lt;p&gt;That&#39;s makes our recommendations for &lt;em&gt;top 10 best laptops for writers&lt;/em&gt;.  If you are a novice or a seasonal writer there is no point investing $1000 in a laptop.  Budget or mid-range laptops from the list will do.  On the other hand professional writers need powerful machines to cope up with their work all day.  For them a high-end laptop would be the wise choice.  However all of the above recommended laptops are great for writing with well-spaced backlit keyboard, comfortable palm rest, high definition screen and optimal performance.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2017/01/best-laptops-for-writers-writing.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxdrFJ_vG4XEE4vN98V2qxIIZm3YJeZqGU5CyWlwedNhSHdpOkFNgm7i9-0GHJ5tXEh_SnmP0MChcZXQfs7i0DpPAXkhRl5quzG3lcsyLFpzkGnpU5VfeiJsq7bX8ZxUDQFmYX_VR2Xm_6/s72-c/top-10-laptops-for-writers-writing.jpg" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-7652249968202451381</guid><pubDate>Thu, 01 Mar 2018 13:28:00 +0000</pubDate><atom:updated>2018-03-01T18:58:12.315+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">MySQL</category><title>How to Find the Second Highest Salary with MySQL Query</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! Today&#39;s post is about a popular interview question, which is the sql query to &lt;strong&gt;find the second highest salary&lt;/strong&gt;. Most freshers would have faced this question in their interviews. There is not one single solution for this. You can approach in different ways to get the second maximum salary from the database. Here I&#39;m going to show you some of the best possible ways you can write the sql query to fetch the salary that is second highest.&lt;/p&gt;

&lt;p&gt;I&#39;ve tried these queries on MySQL but it also works with other relational databases such as MSSQL Server, Oracle etc., that uses SQL.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;sql query find second highest salary&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_4O-V4ikZJOGQfAvsMJPswY2HH5bmpnlfsbT3TDvLd38Ki8vX99Q_xmGYkgecf6xjAh1DqLqJq5KgV89LiuJ9ARkyCH8pCZlN2ewxOzAAbSBVhzN_obcm5Ymnd3naDXo3R7c2L30jK3j5/s1600/mysql-query-find-second-largest-salary.png&quot; title=&quot;Get Second Maximum Salary&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;Finding the Second Highest Salary:&lt;/h2&gt;

&lt;p&gt;Consider the following table. It consists of a set of employee records and we are going to use in our queries to get salary that is second largest.&lt;/p&gt;

&lt;h4&gt;Table Name: Employees&lt;/h4&gt;

&lt;table class=&quot;table1&quot;&gt;
    &lt;thead&gt;
        &lt;th&gt;ID&lt;/th&gt;
        &lt;th&gt;Name&lt;/th&gt;
        &lt;th&gt;Designation&lt;/th&gt;
        &lt;th&gt;Salary&lt;/th&gt;
    &lt;/thead&gt;
    &lt;tr&gt;
        &lt;td&gt;1&lt;/td&gt;
        &lt;td&gt;Colleen Hurst&lt;/td&gt;
        &lt;td&gt;Regional Director&lt;/td&gt;
        &lt;td&gt;205500&lt;/td&gt;
    &lt;/tr&gt;    
    &lt;tr&gt;
        &lt;td&gt;2&lt;/td&gt;
        &lt;td&gt;Garrett Winters&lt;/td&gt;
        &lt;td&gt;Accountant&lt;/td&gt;
        &lt;td&gt;170750&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;3&lt;/td&gt;
        &lt;td&gt;Quinn Flynn&lt;/td&gt;
        &lt;td&gt;Support Lead&lt;/td&gt;
        &lt;td&gt;342000&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;4&lt;/td&gt;
        &lt;td&gt;Jena Gaines&lt;/td&gt;
        &lt;td&gt;Software Engineer&lt;/td&gt;
        &lt;td&gt;133600&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;5&lt;/td&gt;
        &lt;td&gt;Brielle William&lt;/td&gt;
        &lt;td&gt;Regional Director&lt;/td&gt;
        &lt;td&gt;372000&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;

&lt;h3&gt;1. Using Subquery:&lt;/h3&gt;

&lt;p&gt;Here is the simple query to find the highest salary from the above &#39;Employees&#39; table. It uses the &lt;code&gt;max()&lt;/code&gt; aggregate function to return the maximum value of a field (or expression).&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
SELECT MAX(Salary) FROM Employees

// output: 372000
&lt;/pre&gt;

&lt;p&gt;Simply nesting this query will give you the second highest salary. It excludes the maximum salary from the table using subquery and fetches the maximum salary again.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
SELECT MAX(Salary) FROM Employees WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employees)

// output: 342000
&lt;/pre&gt;

&lt;p&gt;Below is the slightly different version of this sub query and it uses &lt;code&gt;&amp;lt;&lt;/code&gt; (less than) operator instead of &lt;code&gt;NOT IN&lt;/code&gt;&lt;p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
SELECT MAX(Salary) FROM Employees WHERE Salary &amp;lt; (SELECT MAX(Salary) FROM Employees)

// output: 342000
&lt;/pre&gt;

&lt;h3&gt;2. Using Limit Clause:&lt;/h3&gt;

&lt;p&gt;To find the second highest salary without sub-query, you can use use &lt;code&gt;LIMIT&lt;/code&gt; and &lt;code&gt;ORDER BY&lt;/code&gt; clause.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
SELECT Salary FROM Employees ORDER BY Salary DESC LIMIT 1,1

// Output: 342000
&lt;/pre&gt;

&lt;p&gt;The query will simply sort the salary field in descending order and fetch the second row (2nd largest) from the result set. If you have duplicate values in salary column, then use &lt;code&gt;DISTINCT&lt;/code&gt; to select only unique values.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You can generalize the limit query to find out the n-th highest salary like this,&lt;/strong&gt;&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
SELECT DISTINCT(Salary) FROM Employees ORDER BY Salary DESC LIMIT (n-1),1
&lt;/pre&gt;

&lt;h3&gt;3. With Self Join:&lt;/h3&gt;

&lt;p&gt;Another interesting way to write the query is to use self join. It takes up the cross-product of the table with itself, exclude the highest salary from the lot and then get the maximum salary from the remaining rows - which gives you the second-maximum.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
Select MAX(Emp1.Salary) FROM Employees Emp1, Employees Emp2 WHERE Emp1.Salary &amp;lt; Emp2.Salary

// output: 342000
&lt;/pre&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2015/06/how-to-backup-restore-mysql-database-command-line.html&quot;&gt;How to Take Backup and Restore MySQL Database&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2017/01/simple-ajax-pagination-in-jquery-php-pdo-mysql.html&quot;&gt;AJAX Pagination using PHP PDO, MySQL &amp; jQuery&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Those are some of the &lt;em&gt;popular ways to find the second maximum salary&lt;/em&gt;. Not only for salary, but the concept can be generalized to find age or other similar fields. I hope this tutorial is useful to you. Please share this post on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/03/find-second-highest-salary-mysql.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_4O-V4ikZJOGQfAvsMJPswY2HH5bmpnlfsbT3TDvLd38Ki8vX99Q_xmGYkgecf6xjAh1DqLqJq5KgV89LiuJ9ARkyCH8pCZlN2ewxOzAAbSBVhzN_obcm5Ymnd3naDXo3R7c2L30jK3j5/s72-c/mysql-query-find-second-largest-salary.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-4439082438781864327</guid><pubDate>Mon, 26 Feb 2018 13:15:00 +0000</pubDate><atom:updated>2018-02-26T18:45:55.230+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">php</category><title>How to Display Random Image from Folder in PHP</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! This is a quick tutorial about &lt;strong&gt;displaying random image from folder in php&lt;/strong&gt;. It will be useful if you want to include featured section area on websites. Usually site owners will showcase their products or services in the prominent section with attractive pictures. And all these images will come from a folder and rotated through at regular time interval. A random image will be picked up from the lot one at a time and displayed here.&lt;/p&gt;

&lt;p&gt;Let&#39;s see how to implement this random image selection process. PHP offers a rich set of native functions to handle directory and files. And they are more than enough for the task we are going to do.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;php display random image from folder&quot; border=&quot;0&quot; data-original-height=&quot;315&quot; data-original-width=&quot;560&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMZ-iBT5-aa3Y5iq_JPbn8LTo16qo1wqKCD8mg-C8PW_-BKzDB_wm0u9tOzoZBM25bhT-sa-NWdeWxuDhi1PnkFxr-IOyBHg80GDs6vNsaQxmQakTL_yJvjRHxBG5DmDYBht2ufuanY_ON/s1600/php-display-random-image-from-folder.png&quot; title=&quot;Display Random Image&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;PHP - Displaying Random Image from Folder:&lt;/h2&gt;

&lt;p&gt;As for the process goes, we have to use &lt;code&gt;scandir()&lt;/code&gt; function to read all the files from a given folder and make a random pick in the lot. Just follow the below steps to choose a random image file in a directory and display it on the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step-1)&lt;/strong&gt; First define the path to the image folder.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$dir_path = &quot;images&quot;;
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step-2)&lt;/strong&gt; Next read all the filenames into an array. For this we have to use scandir() method.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$files = scandir($dir_path);
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step-3)&lt;/strong&gt; Now select a random image file from the array. For this, you have to create a random index using &lt;code&gt;rand()&lt;/code&gt; function and get the file name.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$count = count($files);
$index = rand(2, ($count-1));
$filename = $files[$index];
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;Step-4)&lt;/strong&gt; Finally display the chosen image in the browser. You must use &lt;code&gt;&amp;lt;img&amp;gt;&lt;/code&gt; tag to display the image.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
echo &#39;&amp;lt;img src=&quot;&#39;.$dir_path.&quot;/&quot;.$filename.&#39;&quot; alt=&quot;&#39;.$filename.&#39;&quot;&amp;gt;&#39;;
&lt;/pre&gt;

&lt;p&gt;That&#39;s it! You have successfully displayed a random image in a directory.&lt;/p&gt;

&lt;h3&gt;PHP Function:&lt;/h3&gt;

&lt;p&gt;Here I have created &lt;code&gt;getRandomImage()&lt;/code&gt; function to display random picture. It takes up the directory path as a parameter and returns an image from the same directory.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
function getRandomImage($dir_path = NULL){
    if(!empty($dir_path)){
        $files = scandir($dir_path);
        $count = count($files);
        if($count &amp;gt; 2){
            $index = rand(2, ($count-1));
            $filename = $files[$index];
            return &#39;&amp;lt;img src=&quot;&#39;.$dir_path.&quot;/&quot;.$filename.&#39;&quot; alt=&quot;&#39;.$filename.&#39;&quot;&amp;gt;&#39;;
        } else {
            return &quot;The directory is empty!&quot;;
        }
    } else {
        return &quot;Please enter valid path to image directory!&quot;;
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;h3&gt;Usage:&lt;/h3&gt;

&lt;p&gt;You have to call the above function like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
echo getRandomImage(&quot;images&quot;);
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Every time you run the code, it will select and display some random picture from the folder.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;
&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2016/11/jquery-php-image-gallery-from-folder-bootstrap.html&quot;&gt;Dynamic Image Gallery from Folder with PHP &amp; Bootstrap&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2016/12/country-state-city-dropdown-list-using-jquery-ajax-php.html&quot;&gt;Country State City Dropdown List using PHP and AJAX&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Likewise, you can &lt;em&gt;display random image from the folder in php&lt;/em&gt;. To read the filenames, you also can use &lt;code&gt;glob()&lt;/code&gt; function which return the filenames from a folder that matches a specific pattern. Hope this post is useful to you. Please share it on social media if you like it.&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2018/02/display-random-image-from-folder-php.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMZ-iBT5-aa3Y5iq_JPbn8LTo16qo1wqKCD8mg-C8PW_-BKzDB_wm0u9tOzoZBM25bhT-sa-NWdeWxuDhi1PnkFxr-IOyBHg80GDs6vNsaQxmQakTL_yJvjRHxBG5DmDYBht2ufuanY_ON/s72-c/php-display-random-image-from-folder.png" height="72" width="72"/><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-6789532719480522808</guid><pubDate>Sat, 24 Feb 2018 14:34:00 +0000</pubDate><atom:updated>2018-02-25T03:15:46.148+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CodeIgniter</category><category domain="http://www.blogger.com/atom/ns#">CodeIgniter Basics</category><category domain="http://www.blogger.com/atom/ns#">CodeIgniter File Upload</category><category domain="http://www.blogger.com/atom/ns#">File Upload</category><title>Upload Multiple Images &amp; Files in CodeIgniter Example</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Hi! In this post, we&#39;ll see &lt;strong&gt;how to upload multiple images and files in codeigniter&lt;/strong&gt;.  &lt;a href=&quot;http://kodingmadesimple.com/&quot;&gt;Kodingmadesimple&lt;/a&gt; has a nice tutorial about &lt;a href=&quot;http://www.kodingmadesimple.com/2015/02/image-file-upload-in-codeigniter-validations-examples.html&quot;&gt;codeigniter file upload&lt;/a&gt; process.  Normal file uploading has a limitation which is you can only upload a single file/image at a time.  What if you want to upload multiple files or images in codeigniter in one go? Is it possible to do that? The answer is YES! You can! Here I&#39;ll show you an example about multiple file upload in codeigniter.&lt;/p&gt;

&lt;h2&gt;CodeIgniter Upload Multiple Files/Images:&lt;/h2&gt;

&lt;p&gt;For this file uploading process you&#39;ll need a folder in the server to store all your uploaded files.  Just create a folder named &lt;strong&gt;&#39;uploads&#39;&lt;/strong&gt; inside the application root and make sure to enable &lt;strong&gt;&#39;write&#39;&lt;/strong&gt; access to it.&lt;/p&gt;

&lt;p&gt;Next you need to create user interface to upload files.  So create a code igniter view with a form and add file control &amp; submit button to it.  Set the name of the file field as array and add &lt;strong&gt;&#39;multiple&#39;&lt;/strong&gt; attribute to enable multi-select.  Without this setting, you&#39;ll only be able to select single file at a time to upload.&lt;/p&gt;

&lt;p&gt;Also set form type to &lt;strong&gt;&#39;multipart&#39;&lt;/strong&gt; for the uploading process to work.  Here is the view I have created for the demo.&lt;/p&gt;

&lt;h2&gt;View (multiple_upload_view.php):&lt;/h2&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;div class=&quot;container&quot;&amp;gt;
    &amp;lt;div class=&quot;row&quot;&amp;gt;
        &amp;lt;div class=&quot;col-xs-8 col-xs-offset-2 well&quot;&amp;gt;
            &amp;lt;?php echo form_open_multipart(&#39;multiple_upload/upload&#39;);?&amp;gt;
                &amp;lt;legend&amp;gt;Select Files to Upload:&amp;lt;/legend&amp;gt;
                &amp;lt;div class=&quot;form-group&quot;&amp;gt;
                    &amp;lt;input name=&quot;usr_files[]&quot; type=&quot;file&quot; multiple=&quot;&quot; /&amp;gt;
                    &amp;lt;span class=&quot;text-danger&quot;&amp;gt;&amp;lt;?php if (isset($error)) { echo $error; } ?&amp;gt;&amp;lt;/span&amp;gt;
                &amp;lt;/div&amp;gt;
                &amp;lt;div class=&quot;form-group&quot;&amp;gt;
                    &amp;lt;input type=&quot;submit&quot; value=&quot;Upload&quot; class=&quot;btn btn-primary btn-block&quot;/&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;?php echo form_close(); ?&amp;gt;
            &amp;lt;?php if (isset($success_msg)) { echo $success_msg; } ?&amp;gt;
        &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;

&lt;p&gt;This view would create a html form similar to this,&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;upload-multiple-images-files-codeigniter-example&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZLC6LwAByZ1_cV4zLqJ6mwvBfuv0RTyPx0UE3Pj1bKbuu6qZE7gJ2E47Ut9NMJRnAian2vjwqRR1wscr61R34w_MLTT_YFiXy_nFUDlo8JeOlFxDGi2M6CO4BbcFEahF90mIxR6hl2MtZ/s1600/upload-multiple-images-files-codeigniter-example.png&quot; title=&quot;Upload Multiple Image Files in Codeigniter&quot; /&gt;&lt;/div&gt;

&lt;p&gt;Next you need to create a controller where you receive the files from the file control and loop through the &lt;code&gt;$_FILES&lt;/code&gt; array one by one and upload them to server using &lt;code&gt;$this-&amp;gt;upload-&amp;gt;do_upload()&lt;/code&gt; function.  By default this function read &amp; uploads the file from the form field with name &lt;strong&gt;&#39;userfile&#39;&lt;/strong&gt;.  If you want to use some other name then you should pass it as function parameter to do_upload().&lt;/p&gt;

&lt;h2&gt;Controller (multiple_upload.php):&lt;/h2&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
class multiple_upload extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this-&amp;gt;load-&amp;gt;helper(array(&#39;form&#39;, &#39;url&#39;));
    }

    function index()
    {
        //load file upload form
        $this-&amp;gt;load-&amp;gt;view(&#39;multiple_upload_view&#39;);
    }

    function upload()
    {
        // set upload preferences
        $config[&#39;upload_path&#39;] = &#39;./uploads/&#39;;
        $config[&#39;allowed_types&#39;] = &#39;txt|pdf&#39;;
        $config[&#39;max_size&#39;]    = &#39;150&#39;;

        //initialize upload class
        $this-&amp;gt;load-&amp;gt;library(&#39;upload&#39;, $config);
        
        $upload_error = array();
        
        for($i=0; $i&amp;lt;count($_FILES[&#39;usr_files&#39;][&#39;name&#39;]); $i++)
        {
            $_FILES[&#39;userfile&#39;][&#39;name&#39;]= $_FILES[&#39;usr_files&#39;][&#39;name&#39;][$i];
            $_FILES[&#39;userfile&#39;][&#39;type&#39;]= $_FILES[&#39;usr_files&#39;][&#39;type&#39;][$i];
            $_FILES[&#39;userfile&#39;][&#39;tmp_name&#39;]= $_FILES[&#39;usr_files&#39;][&#39;tmp_name&#39;][$i];
            $_FILES[&#39;userfile&#39;][&#39;error&#39;]= $_FILES[&#39;usr_files&#39;][&#39;error&#39;][$i];
            $_FILES[&#39;userfile&#39;][&#39;size&#39;]= $_FILES[&#39;usr_files&#39;][&#39;size&#39;][$i];
            
            if (!$this-&amp;gt;upload-&amp;gt;do_upload())
            {
                // fail
                $upload_error = array(&#39;error&#39; =&amp;gt; $this-&amp;gt;upload-&amp;gt;display_errors());
                $this-&amp;gt;load-&amp;gt;view(&#39;multiple_upload_view&#39;, $upload_error);
                break;
            }
        }
        
        // success
        if ($upload_error == NULL)
        {
            $data[&#39;success_msg&#39;] = &#39;&amp;lt;div class=&quot;alert alert-success text-center&quot;&amp;gt;Finished uploading...&amp;lt;/div&amp;gt;&#39;;
            $this-&amp;gt;load-&amp;gt;view(&#39;multiple_upload_view&#39;, $data);
        }
    }
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;In the above controller I have added a function upload() to loop through the file array, upload files one by one and display a success message once the process is complete.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;codeigniter-upload-multiple-files-success&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhthj_xe0S_YKpHPyQjtIOx7jhM-1IjHc6e6I6LJKq81tUPmbcgaXNBX3XKYAjt3a-m3REpIKMc8WMzMSorJtZlgSWzuUmsNSlu4HGt5BoxCIQEFKUalXTopz6VS0beNtqteodwsNsXVk08/s1600/codeigniter-upload-multiple-files-success.png&quot; title=&quot;CodeIgniter Multiple Image Upload - Success&quot; /&gt;&lt;/div&gt;

&lt;p&gt;If anything goes wrong at the time of uploading, then error message will be shown to the user.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;codeigniter-multiple-image-upload-error&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhaCq3adKpa15vKSHZ2LTFEwHwO-h_sBGPJ3SHv12KtS8jivZoKwULNLIJ45XiN93S0iPVgxCxwVRlXt6gqyAdDPas1_TTeiiNl4TEOClkMyWxMDPVxK9iai3DsuivrKMkc6jBFa-uR7Di_/s1600/codeigniter-multiple-image-upload-error.png&quot; title=&quot;CodeIgniter Multiple File Upload - Error&quot; /&gt;&lt;/div&gt;

&lt;p&gt;If you want to &lt;strong&gt;restrict uploading to images alone&lt;/strong&gt;, then set the configuration to accept only image file types like this,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$config[&#39;allowed_types&#39;] = &#39;png|gif|jpg|jpeg&#39;;
&lt;/pre&gt;

&lt;p&gt;To accept all sorts of file types use &#39;*&#39; instead (default),&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
$config[&#39;allowed_types&#39;] = &#39;*&#39;;
&lt;/pre&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;
&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/01/resize-image-create-thumbnail-codeigniter.html&quot;&gt;Image Upload, Resize and Thumbnail Creation in CodeIgniter&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2016/06/codeigniter-login-and-registration-tutorial-source-code.html&quot;&gt;CodeIgniter Login and Registration System with Session&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That explains about &lt;em&gt;uploading multiple images and files in php codeigniter&lt;/em&gt;.  I have given the logic.  Just customize it to suit your needs.  Meet you another interesting tutorial :)&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2016/09/upload-multiple-images-files-in-codeigniter-example.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZLC6LwAByZ1_cV4zLqJ6mwvBfuv0RTyPx0UE3Pj1bKbuu6qZE7gJ2E47Ut9NMJRnAian2vjwqRR1wscr61R34w_MLTT_YFiXy_nFUDlo8JeOlFxDGi2M6CO4BbcFEahF90mIxR6hl2MtZ/s72-c/upload-multiple-images-files-codeigniter-example.png" height="72" width="72"/><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-4505192626920795935.post-6087580655786616473</guid><pubDate>Sat, 24 Feb 2018 08:30:00 +0000</pubDate><atom:updated>2018-02-25T03:14:36.929+05:30</atom:updated><category domain="http://www.blogger.com/atom/ns#">CodeIgniter</category><category domain="http://www.blogger.com/atom/ns#">CodeIgniter File Upload</category><category domain="http://www.blogger.com/atom/ns#">File Upload</category><title>Simple Image and File Upload in CodeIgniter with Validations &amp; Examples</title><description>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;

&lt;p&gt;Codeigniter provides a wide number of helper class and libraries for rapid application development.  &lt;strong&gt;Upload library is one among them that makes file uploading process in Codeigniter a breeze.&lt;/strong&gt;  We&#39;ll see how to do file and image upload in codeigniter in this tutorial. File and Image uploading are similar since images are themselves files.  But there are options for you to restrict the uploading process specific to images files alone and we&#39;ll see it below.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center; display: none;&quot;&gt;
&lt;img alt=&quot;file-upload-in-codeigniter-example-validations&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg4VXz5H-MJn6IbvciplzvlCmhimaLkBjStSrmxYl7GglpTZ0nokLFBaedZcqLknRyYR7TiRSfT5tjxRE5taRdtBqlMcvyOrUgStNdNi-1IqlDNKbIqAwKMkX73fjtFshmp-9ILT3QElgc/s1600/file-upload-in-codeigniter-example-validations.png&quot; title=&quot;File Upload in Codeigniter with Validation and Example&quot; /&gt;&lt;/div&gt;

&lt;h2&gt;File Upload in CodeIgniter&lt;/h2&gt;

&lt;p&gt;First of all, we need a destination folder to store all the uploaded files.  So create a folder named &lt;strong&gt;&#39;uploads&#39;&lt;/strong&gt; in the root folder.  Make sure it is writable for the uploading process to work.&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2014/08/how-to-create-login-form-codeigniter-mysql-twitter-bootstrap.html&quot;&gt;How to Create Login Page in CodeIgniter &amp; MySQL&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2015/03/how-to-send-email-in-codeigniter-smtp.html&quot;&gt;How to Send Email in CodeIgniter using Gmail&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2015/04/php-codeigniter-pagination-twitter-bootstrap-styles.html&quot;&gt;CodeIgniter Pagination System using Bootstrap&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;Create Controller&lt;/h4&gt;

&lt;p&gt;Create a controller file &lt;strong&gt;&#39;uploadfile.php&#39;&lt;/strong&gt; inside &#39;application\controllers&#39; folder in codeigniter.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
class uploadfile extends CI_Controller {

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;function __construct()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;parent::__construct();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$this-&amp;gt;load-&amp;gt;helper(array(&#39;form&#39;, &#39;url&#39;));
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//index function
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;function index()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//load file upload form
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$this-&amp;gt;load-&amp;gt;view(&#39;upload_file_view&#39;);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//file upload function
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;function upload()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//set preferences
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$config[&#39;upload_path&#39;] = &#39;./uploads/&#39;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$config[&#39;allowed_types&#39;] = &#39;txt|pdf&#39;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$config[&#39;max_size&#39;]&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;= &#39;100&#39;;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//load upload class library
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$this-&amp;gt;load-&amp;gt;library(&#39;upload&#39;, $config);

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;if (!$this-&amp;gt;upload-&amp;gt;do_upload(&#39;filename&#39;))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// case - failure
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$upload_error = array(&#39;error&#39; =&amp;gt; $this-&amp;gt;upload-&amp;gt;display_errors());
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$this-&amp;gt;load-&amp;gt;view(&#39;upload_file_view&#39;, $upload_error);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;{
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// case - success
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$upload_data = $this-&amp;gt;upload-&amp;gt;data();
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$data[&#39;success_msg&#39;] = &#39;&amp;lt;div class=&quot;alert alert-success text-center&quot;&amp;gt;Your file &amp;lt;strong&amp;gt;&#39; . $upload_data[&#39;file_name&#39;] . &#39;&amp;lt;/strong&amp;gt; was successfully uploaded!&amp;lt;/div&amp;gt;&#39;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$this-&amp;gt;load-&amp;gt;view(&#39;upload_file_view&#39;, $data);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}
}
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;The &lt;code&gt;upload()&lt;/code&gt; method in the codeigniter controller is where the actual &lt;a href=&quot;http://www.kodingmadesimple.com/2014/11/simple-file-upload-php-example-script.html&quot;&gt;file upload process&lt;/a&gt; takes place.  Here we load the &#39;upload&#39; library with the statement &lt;code&gt;$this-&gt;load-&gt;library(&#39;upload&#39;, $config); &lt;/code&gt;.  The $config is the array where we set preferences to control the uploading process.  This is where we define the file uploading path, allowed &lt;a href=&quot;http://en.wikipedia.org/wiki/Filename_extension&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;file extensions&lt;/a&gt;, maximum file size etc.&lt;/p&gt;

&lt;p&gt;This controller upload() method will be invoked on form submission, and the file will be validated and shows the validation error in case it fails.  Else it will upload the file to the destination folder.&lt;/p&gt;

&lt;p&gt;We have used some of the important methods of the &#39;upload&#39; class library in our controller.&lt;/p&gt;

&lt;p&gt;&lt;ul&gt;&lt;li&gt;The callback, &lt;code&gt;$this-&gt;upload-&gt;do_upload()&lt;/code&gt; will upload the file selected in the given field name to the destination folder.  Note that the parameter to this method is optional and if it is not mentioned, then it expects the file from the input field with name &lt;strong&gt;&#39;userfile&#39;&lt;/strong&gt;.  So if you set the file input with name other than &#39;userfile&#39; make sure you pass the field name as parameter to the &lt;code&gt;do_upload()&lt;/code&gt; function.&lt;/li&gt;

&lt;li&gt;The callback &lt;code&gt;$this-&gt;upload-&gt;display_errors()&lt;/code&gt; returns the error message if the do_upload() method returns false.&lt;/li&gt;

&lt;li&gt;And the callback &lt;code&gt;$this-&gt;upload-&gt;data()&lt;/code&gt; returns an array of data related to the uploaded file like the file name, path, size etc.&lt;/li&gt;&lt;/ul&gt;&lt;/p&gt;

&lt;h4&gt;Create View&lt;/h4&gt;

&lt;p&gt;Create the view file &lt;strong&gt;&#39;upload_file_view.php&#39;&lt;/strong&gt; inside &#39;application\views&#39; folder.  This view file contains a simple upload form with file input and a submit button.&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;title&amp;gt;CodeIgniter File Upload Form&amp;lt;/title&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;!-- load bootstrap css file --&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;link href=&quot;&amp;lt;?php echo base_url(&quot;assets/bootstrap/css/bootstrap.css&quot;); ?&amp;gt;&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;div class=&quot;container&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;row&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;col-md-6 col-md-offset-3 well&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;legend&amp;gt;CodeIgniter File Upload Demo&amp;lt;/legend&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;?php echo form_open_multipart(&#39;uploadfile/upload&#39;);?&amp;gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;fieldset&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;form-group&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;row&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;col-md-12&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;label for=&quot;filename&quot; class=&quot;control-label&quot;&amp;gt;Select File to Upload&amp;lt;/label&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;form-group&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;row&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;col-md-12&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input type=&quot;file&quot; name=&quot;filename&quot; size=&quot;20&quot; /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;span class=&quot;text-danger&quot;&amp;gt;&amp;lt;?php if (isset($error)) { echo $error; } ?&amp;gt;&amp;lt;/span&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;form-group&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;row&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;div class=&quot;col-md-12&quot;&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;input type=&quot;submit&quot; value=&quot;Upload File&quot; class=&quot;btn btn-primary&quot;/&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/fieldset&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;?php echo form_close(); ?&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;?php if (isset($success_msg)) { echo $success_msg; } ?&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;

&lt;p&gt;The above view will produce an upload form like this.&lt;/p&gt;

&lt;table align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;tr-caption-container&quot; style=&quot;margin-left: auto; margin-right: auto; text-align: center;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: center;&quot;&gt;&lt;img alt=&quot;codeigniter-file-upload-demo-form&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYH-qr18RPFKh6zHu8u3mMn2WEPFU-7PUiy77uf5Vj_Z4LYrs80x6s84MgW1n5RaOJ7JcD1gJISz1Ut_Ec1y82z0tMREqOAUaIX4hVT6vI-Rwue4a650PXlq2KsDdys7YFXTnZa4SiuZMu/s1600/codeigniter-file-upload-demo-form.png&quot; title=&quot;CodeIgniter File Upload Demo Form&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;tr-caption&quot; style=&quot;text-align: center;&quot;&gt;CodeIgniter File Upload Demo Form&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
  
&lt;p&gt;Generally I use bootstrap css framework to design the html forms for all my tutorials.  This tutorial is no exception and I have used &lt;a href=&quot;http://getbootstrap.com/components/&quot; target=&quot;_blank&quot; rel=&quot;nofollow&quot;&gt;bootstrap components&lt;/a&gt; to give a nice look and feel to our upload form.  Also I have set the form type to &lt;strong&gt;&#39;multipart&#39;&lt;/strong&gt; for the file uploading to work. (If you are a newbie to bootstrap then take a look at this &lt;a href=&quot;http://www.kodingmadesimple.com/2014/06/integrate-twitter-bootstrap3-with-codeigniter-framework.html&quot;&gt;tutorial on using bootstrap with codeigniter php framework&lt;/a&gt; to learn more).&lt;/p&gt;

&lt;p&gt;When the user submits the form, it will be validated against the preferences set by the $config[] array.  If the file is not selected or any other &lt;a href=&quot;http://www.kodingmadesimple.com/2014/04/use-php-preg-match-function-for-form-validation.html&quot;&gt;form validation&lt;/a&gt; error occurs, it is displayed below the file input like this.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;file-upload-validation-error&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijyh_eGDrHUsqsHorlZjS5u-_mfN7orvy0jSwk_y5Ff-S9upG8jm3S8ixjfRxWxQm5mMY3YYonc6eQR5KtSJIgAGOiP4TXSRLsO4TAEY2dfh4EzGb2W8pPxHHxeUhOMNQ9zJ3XN0wxP6tM/s1600/file-upload-validation-error.png&quot; title=&quot;File Upload Validation Error&quot; /&gt;&lt;/div&gt;

&lt;p&gt;If the validation succeeds and the file is uploaded successfully to the destination folder, a success message will be displayed at the bottom of the form like this.&lt;/p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;img alt=&quot;file-upload-validation-success&quot; border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSyHWYvLFETIqHUAY-javOGLf3LJWrjgBOjnD58Iy9GuQmuc-E-wA6WBJdyrUrR2-xCI1mZH7gUYCkUgFITbZkMhC12J5IgVLNzkOqDP51uV9oT5ClQaSCbmf4s7I5In8bitd9k6HyVol7/s1600/file-upload-validation-success.png&quot; title=&quot;File Upload Validation Success&quot; /&gt;&lt;/div&gt;

&lt;h3&gt;Uploading Images in CodeIgniter&lt;/h3&gt;

&lt;p&gt;If you want to restrict the user to upload only image files in codeigniter, then you can set the preferences to something like this in the controller file,&lt;/p&gt;

&lt;pre class=&quot;prettyprint lang-php codebk&quot;&gt;
&amp;lt;?php
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$config[&#39;upload_path&#39;] = &#39;./uploads/&#39;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$config[&#39;allowed_types&#39;] = &#39;png|jpg|gif&#39;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$config[&#39;max_size&#39;] = &#39;150&#39;;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$config[&#39;max_width&#39;] = &#39;1024&#39;; /* max width of the image file */
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$config[&#39;max_height&#39;] = &#39;768&#39;; /* max height of the image file */
?&amp;gt;
&lt;/pre&gt;

&lt;p&gt;Hence in this way you can restrict the users to upload only images.  Moreover all those image files should fall under the maximum file size, width and height set by you :).&lt;/p&gt;

&lt;strong&gt;Read Also:&lt;/strong&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2018/01/resize-image-create-thumbnail-codeigniter.html&quot;&gt;How to Resize Uploaded Image and Create Thumbnail in CodeIgniter&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2016/09/upload-multiple-images-files-in-codeigniter-example.html&quot;&gt;How to Upload Multiple Files &amp; Images in CodeIgniter (At Once)&lt;/a&gt;&lt;/li&gt;
 &lt;li&gt;&lt;a href=&quot;http://www.kodingmadesimple.com/2016/09/retrieve-data-from-database-ajax-codeigniter.html&quot;&gt;Fetch Data From Database using AJAX &amp; CodeIgniter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;And that explains the file and image uploading process in codeigniter.&lt;/em&gt;  I hope you like this turorial.  Meet you in another interesting post.  Please don&#39;t forget to share this on your social circle.  Good Day!!!&lt;/p&gt;

&lt;/div&gt;
</description><link>http://www.kodingmadesimple.com/2015/02/image-file-upload-in-codeigniter-validations-examples.html</link><author>noreply@blogger.com (Valli)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg4VXz5H-MJn6IbvciplzvlCmhimaLkBjStSrmxYl7GglpTZ0nokLFBaedZcqLknRyYR7TiRSfT5tjxRE5taRdtBqlMcvyOrUgStNdNi-1IqlDNKbIqAwKMkX73fjtFshmp-9ILT3QElgc/s72-c/file-upload-in-codeigniter-example-validations.png" height="72" width="72"/><thr:total>11</thr:total></item></channel></rss>