In this tutorial you will learn how to implement multiple image upload using CodeIgniter framework. We will cover this tutorial in easy steps with live demo to upload multiple images in CodeIgniter framework and you can also download source code of live demo to use in your projects. File Uploading with CodeIgniter. CodeIgniter has documented the Uploading process very well, by using the File Uploading library. You could take a look at the sample code in the user guide; And also, in order to get a better understanding of the uploading configs, Check the Config items Explanation section at the end of the manual page. Also there are couple of articles/samples about the. Jan 07, 2014 Here's how you can upload images using the CodeIgniter framework. All the images in this answer have been borrowed from the CodeIgniter documentation: The form tag requires the enctype attribute to be set to 'multipart/form-data' to allow file u. How to remove index.php in CodeIgniter; Download and Install Latest CodeIgniter Framework. The source code for the CodeIgniter framework is available on the official CodeIgniter website. If you want to download the latest version of the framework, then you should do it from the official web page.
An advanced image resize/cropping controller that will resize your images on the fly from preset dimensions.
Installation
Configuration
In your config/images.php file you need to specify what preset sizes you will be using for your images:
Each preset has a width and a height. If one of the dimensions are equal to 0, it will automatically calculate a matching width or height to maintain the original ratio. if you specify both dimensions it will automatically crop the resulting image so that it fits those dimensions.
Library
The resize and crop logic is grouped in a library that extends CodeIgniter's 'image_lib' and adds a 'fit' function. You can use this library to resize and crop an image to fit the specified dimensions like this:
The function will return TRUE on sucess or FALSE on failure. Error messages can be read like the normal library with the display_errors() method.
When an image is cropped, the center axis is used by default. If you want to override this behaviour you can specify your own x_axis and y_axis.
Configuration options:
How To Upload Image In Codeigniter Source Code Free Download FullUsage
To resize and crop the images to the preset sizes you need to load the image_helper. This helper has a function image($path, $preset) that will translate a preset to a generated path that contains the dimensions for the controller or that will take you directly to the image if it has already been resized.
Use this helper in your view files like this:
This will eventually translate into:
The reason I add the dimensions to the original filename instead of the preset name is because when you would change the preset's dimensions, it would still load images with the old dimensions that were already generated instead of the new dimensions.
In this tutorial, we are going to look at how you can install and configure CodeIgniter. They are two ways of installation CodeIgniter. You can download the latest version from the CodeIgniter website, or you can use a tool like a composer to automate the installation
In this tutorial, you will learn:
Download and Install Latest CodeIgniter Framework
The source code for the CodeIgniter framework is available on the official CodeIgniter website. If you want to download the latest version of the framework, then you should do it from the official web page.
Step 1) Open the following URL in your browser https://codeigniter.com/
The image below shows the download link to the latest version of the framework
Step 2) Clicking the above link will download the framework as a zipped folder. Unzip the contents of CodeIgniter-3.1.10.zip
Step 3) Let's say you want to create a project called the online store. You can follow the following steps to start your project. Create a new directory in on your development drive, e.g, D:Sitesonline-store
Step 4) Open the contents of CodeIgniter-3.1.10, you should be able to see the following files
Copy the above contents to your project directory, e.g., D:Sitesonline-store
Step 5) Just to make sure everything is ok, open the terminal and start the built-in PHP server
Run the following command
load the following URL into your browser
How To Upload Image In Codeigniter Source Code Free Download Free
If you see above image, all is working well,
What is Composer?
The composer is a package management system for PHP. A package is simply a collection of PHP scripts that work together towards a single goal. Based on this definition, CodeIgniter can even though it's a framework, qualifies to be labeled a package in composer terminologies.
The following image shows how the composer works
The author of CodeIgniter hosts the package at Packagist which is a central repository for PHP packages, etc.
When the developer runs the composer command to download CodeIgniter, Composer communicates with Packagist and downloads the latest release of the package. In addition to installing frameworks such as CodeIgniter, Composer can also be used to;
How to install Composer
Step 1) Load the following URL in your browser https://getcomposer.org/download/
Download the setup and follow the installation instructions.
Step 2) Open the command prompt/terminal Escan activation code free download.
Run the following command
You will see the following results
If you can see the above results, then congratulations, you have successfully installed the composer.
Let's now create a new project called online-store
Run the following command
HERE,
You should be able to see results that is similar to the following
If you are a big fan of commands on the terminal then this is the way to go otherwise you can use the good old fashioned download the zipped file, unzip and happy coding.
CodeIgniter Config Files
Now that we have successfully installed CodeIgniter let's look at the configuration directory
The configuration directory is located in
HERE,
CodeIgniter Configurations
let's now make some of the most common settings in CodeIgniter
Base URL
Sets the base URL. If its blank then CodeIgniter will set it for you automatically. If you want to be explicit about your base URL, then you can use the something like the following
HERE,
Class Prefix
CodeIgniter uses the prefix CI_Classname. As a best practice and to avoid collisions with internal classes, you can prefix your class, i.e., MY_Classname. The following line is used to set your class prefix
Query Strings
These are parameters that are visited in the URL, i.e., example.com/index.php?q=eggs. If you would like to use such URLs, then you will have to set
Other settings
They are many settings that you can set in config.php including date formats, cache and view paths, etc. much of what you configure depends on your application needs
How to remove index.php in CodeIgniter
CodeIgniter is an MVC framework. This means it has a single entry point into the application which is index.php. It doesn't matter what URL you access. The all go through index.php. by default, index.php is shown in the URL as shown in the example below
The URL looks longer and weird. The good thing is you can configure CodeIgniter to remove that.
Open application/config/config.php
Locate the following line
HERE,
Next, we need to create the .htaccess that rewrites the URLs
Add a new file .htacces in the root directory of the application
Add the following code
HERE,
Summary
Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |