image-select

Insert a link above the image to change it and view the new one using ajax - just like facebook
12 followers

Image View Select to Change

Requirements

Yii 1.1 or above - tested on Yii 1.1.11 and above

Demo

http://yii.nefya.com

Usage

  • extract inside extensions directory
  • be sure that your extensions are imported

/config/main.php

'import'=>array(
                ...
                'application.extensions.*',
                ...
         ),
  • add this to your view:
<?php
   $this->widget('ext.imageSelect.ImageSelect',  array(
        'path'=>'path/to/current/image',
        'alt'=>'alt text',
        'uploadUrl'=>'url that accepts the uploaded image and returns the new path',
        'htmlOptions'=>array()
   ));
?>
  • In your controller you can catch the uploaded file like this sample upload action
public function actionUpload(){
    $file = CUploadedFile::getInstanceByName('file');
    // Do your business ... save on file system for example,
    // and/or do some db operations for example
    $file->saveAs('images/'.$file->getName());
    // return the new file path
    echo Yii::app()->baseUrl.'/images/'.$file->getName();
}

Change Log

  • 1.4
    • Bug fix - hide the loading div after loading the new image instead of after uploading it
  • 1.3
    • Bug fix - for multi instance inside one page
  • 1.2
    • Adding the public property $text to facilitate internationalization
  • 1.1
    • Adding loader image while loading the new one
  • 1.0
    • Initial upload

Resources

Total 6 comments

#12201 report it
Amr Bedair at 2013/03/06 03:06am
Re: Example - 'url' portion

Here is an example

'uploadUrl'=>$this->createUrl('upload', array('attr'=>'logo'))

about the action, as mentioned above, you can catch the file and do anything with it

#12199 report it
skworden at 2013/03/05 08:57pm
Example

Can you please give an example of the 'url' portion. I have tried numerous ways and can't get it to work. How could I use a model behaivour to change the image. i.e.

public function behaviors()
    {
        return array(
        'image' => array(
            'class' => 'ext.AttachmentBehavior.AttachmentBehavior',
            # Should be a DB field to store path/filename
            'attribute' => 'filename',
            # Default image to return if no image path is found in the DB
            'fallback_image' => 'images/default.png',
            'path' => "images/companies/products/:id.:ext",
            'processors' => array(
                array(
                    # Currently GD Image Processor and Imagick Supported
                    'class' => 'GDProcessor',
                    'method' => 'resize',
                    'params' => array(
                    'width' => 540,
                    'height' => 540,
                    'keepratio' => true
                    )
                )
            ),
            'styles' => array(
            # name => size 
            # use ! if you would like 'keepratio' => false
            'thumb' => '!270x270',
            )           
        ),
.....
#11917 report it
Cozumel at 2013/02/13 12:07am
Very Nice

Thank you for this awesome extension!

#11591 report it
Amr Bedair at 2013/01/22 07:03am
demo

http://yii.nefya.com

BTW: I forgot to mention a sample upload action

public function actionUpload(){
    $file = CUploadedFile::getInstanceByName('file');
    $file->saveAs('images/'.$file->getName());
    echo Yii::app()->baseUrl.'/images/'.$file->getName();
}
#11552 report it
Amr Bedair at 2013/01/20 07:27am
Re: Greate work, but

it is simply the url that the widget will post the image file to it, then it will handle this file [may save it to a database or file system, or add it to a model], then it should return the new image's path

#11551 report it
Mahmoud F.Elshazly at 2013/01/20 07:21am
Greate work, but

what is 'uploadUrl' means? is this an action that upload the image and save it then gives the returned path?

Leave a comment

Please to leave your comment.

Create extension