Monthly Archives: November 2012

Vitual Host in Xampp

It is a very important for symfony developer to use virtual host.

I am going to give a simple help here. Any further help will be appreciate …

NameVirtualHost *:80


<VirtualHost *:80>
    DocumentRoot "E:/WebSites/xampp/htdocs"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "E:/WebSites/xampp/htdocs/kh3.3.0"
    ServerName localhost.kohana.dev
    <Directory "E:/WebSites/xampp/htdocs/kh3.3.0">
	Options Indexes FollowSymLinks ExecCGI Includes
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

<VirtualHost *:80>
  DocumentRoot "E:/WebSites/xampp/htdocs/sf-1419/jobeet/web"
    ServerName www.jobeet.com.localhost
  DirectoryIndex index.php
  <Directory "E:/WebSites/xampp/htdocs/sf-1419/jobeet/web">
    AllowOverride All
    Allow from All
  </Directory>

  Alias /sf E:\WebSites\xampp\htdocs\sf-1419\jobeet\lib\vendor\symfony\data\web\sf
  <Directory "E:/WebSites/xampp/htdocs/sf-1419/jobeet/lib/vendor/symfony/data/web/sf">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

In C:\Windows\System32\drivers\etc hosts

127.0.0.1       localhost
127.0.0.1       localhost.kohana.dev #change to match your Virtual Host.
127.0.0.1       www.jobeet.com.localhost #change to match your Virtual Host.
Advertisements

Upload and Resize Image In CodeIgniter

I am having some trouble in image upload and resizing it in CodeIgniter. So I am finally overcome some of the area of it. And now sharing it with all of those who having the same problem.

Please also help me if I was wrong or you have a good example beyond this.

First you must load “image_lib” library of CI.

This is a controller in CI

  

public function imageUpload()
    {
        $data = array();
        if ($this->input->post('submit'))
        {
            if ($_FILES["sc_name"]["name"])
            {
                $path = './upload_image';
                if (!is_dir($path))
                    mkdir($path, 0755);

                $pathMain = './upload_image/source';
                if (!is_dir($pathMain))
                    mkdir($pathMain, 0755);

                $pathThumb = './upload_image/100X100';
                if (!is_dir($pathThumb))
                    mkdir($pathThumb, 0755);

                $path2Thumb = './upload_image/200X200';
                if (!is_dir($path2Thumb))
                    mkdir($path2Thumb, 0755);

                $path3Thumb = './upload_image/300X300';
                if (!is_dir($path3Thumb))
                    mkdir($path3Thumb, 0755);

                $path4Thumb = './upload_image/400X400';
                if (!is_dir($path4Thumb))
                    mkdir($path4Thumb, 0755);

                $result = $this->do_upload("sc_name", $pathMain);

                if (!$result['status'])
                    $data['error_msg'] ="Can not upload Image for " . $result['error'] . " ";
                else
                {
                    $pathThumb = './upload_image/100X100';
                    if (!is_dir($pathThumb))
                        mkdir($pathThumb, 0755);

                    //in other folder
                    if($this->resize_image($pathMain . '/' . $result['upload_data']['file_name'], $pathThumb . '/'.time().'100X100.gif','100','100'))
                        echo 'Image 100X100 resize done';
                    else
                        echo 'Image 100X100 resize failed';
                     if($this->resize_image($pathMain . '/' . $result['upload_data']['file_name'], $path2Thumb . '/'.time().'200X200.gif','200','200'))
                        echo 'Image 200X200 resize done';
                    else
                        echo 'Image 200X200 resize failed';
                     if($this->resize_image($pathMain . '/' . $result['upload_data']['file_name'], $path3Thumb . '/'.time().'300X300.gif','300','300'))
                        echo 'Image 300X300 resize done';
                    else
                        echo 'Image 300X300 resize failed';

                    //in same folder

                     if($this->resize_image($pathMain . '/' . $result['upload_data']['file_name'], time().'100X100.gif','100','100'))
                        echo 'Image 100X100 Same Folder resize done';
                    else
                        echo 'Image 100X100 Same Folder resize failed';
                     if($this->resize_image($pathMain . '/' . $result['upload_data']['file_name'], time().'200X200.gif','200','200'))
                        echo 'Image 200X200 Same Folder resize done';
                    else
                        echo 'Image 200X200 Same Folder resize failed';
                     if($this->resize_image($pathMain . '/' . $result['upload_data']['file_name'], time().'300X300.gif','300','300'))
                        echo 'Image 300X300 Same Folder resize done';
                    else
                        echo 'Image 300X300 Same Folder resize failed';

                }
            }
        }

        $this->load->view('sc/upload_image', $data);
    }

Upload Function inside the CI Controller


function do_upload($htmlFieldName, $path)
    {
        $config['file_name'] = time();
        $config['upload_path'] = $path;
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '2000';
        $config['max_width'] = '2000';
        $config['max_height'] = '2000';
        $this->load->library('upload', $config);
        $this->upload->initialize($config);
        unset($config);
        if (!$this->upload->do_upload($htmlFieldName))
        {
            return array('error' => $this->upload->display_errors(), 'status' => 0);
        } else
        {
            return array('status' => 1, 'upload_data' => $this->upload->data());
        }
    }

Resize Function inside the CI Controller


function resize_image($sourcePath, $desPath, $width = '500', $height = '500')
    {
        $this->image_lib->clear();
        $config['image_library'] = 'gd2';
        $config['source_image'] = $sourcePath;
        $config['new_image'] = $desPath;
        $config['quality'] = '100%';
        $config['create_thumb'] = TRUE;
        $config['maintain_ratio'] = true;
        $config['thumb_marker'] = '';
        $config['width'] = $width;
        $config['height'] = $height;
        $this->image_lib->initialize($config);

        if ($this->image_lib->resize())
            return true;
        return false;
    }

And Finally The form

<?php echo form_open_multipart() ?>

<label for="sc_name">Name</label>
<input type="file" name="sc_name" /><br />
<input type="submit" name="submit" value="Create" />

%d bloggers like this: