/**
  * Widgets run function
  * @param integer $id
  * @param string $attribute
  * @throws CHttpException
  */
 public function run()
 {
     if (Yii::app()->getRequest()->isPostRequest) {
         if (!file_exists($this->uploadPath)) {
             throw new CHttpException(Yii::t('zii', 'Invalid upload path'));
         }
         $uploader = new qqFileUploader($this->allowedExtensions, $this->sizeLimit);
         $result = $uploader->handleUpload($this->uploadPath, true, session_id());
         $gd = new GdImage();
         // step 1: make a copy of the original
         $filePath = $this->uploadPath . '/' . $result['filename'];
         $copyName = $gd->createName($result['filename'], '_FULLSIZE');
         $gd->copy($filePath, $this->uploadPath . '/' . $copyName);
         // step 2: Scale down or up this image so it fits in the browser nicely, lets say 500px is safe
         $oldSize = $gd->getProperties($filePath);
         if ($oldSize['w'] >= $this->resizeWidth) {
             $newSize = $gd->getAspectRatio($oldSize['w'], $oldSize['h'], $this->resizeWidth, 0);
             $gd->resize($filePath, $newSize['w'], $newSize['h']);
         }
         echo json_encode($result);
         Yii::app()->end();
     } else {
         throw new CHttpException(Yii::t('zii', 'Invalid request'));
     }
 }
Example #2
0
I have altered the fileuploader.php to pass back the filename 
which was set and the original filename
*/
require "../scripts" . DS . "fileuploader" . DS . "fileuploader.php";
$allowedExtensions = array('jpeg', 'jpg', 'gif', 'png');
$sizeLimit = 2 * 1024 * 1024;
// max file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload(UPLOAD_DIR, false, md5(uniqid()));
//handleUpload($uploadDirectory, $replaceOldFile=FALSE, $filename='')
/* 
For your crop you should:
1) Make a copy of the full size original
2) Scale down or up this image so it fits in the browser nicely
3) When the crop occurs we will manipulate the full size image
*/
require "gd_image.php";
$gd = new GdImage();
// step 1: make a copy of the original
$filePath = UPLOAD_DIR . $result['filename'];
$copyName = $gd->createName($result['filename'], '_FULLSIZE');
$gd->copy($filePath, UPLOAD_DIR . $copyName);
// step 2: Scale down or up this image so it fits in the browser nicely, lets say 500px is safe
$oldSize = $gd->getProperties($filePath);
$newSize = $gd->getAspectRatio($oldSize['w'], $oldSize['h'], 500, 0);
$gd->resize($filePath, $newSize['w'], $newSize['h']);
// step 3: handled in crop.php!
// to pass data through iframe you will need to encode all html tags
echo json_encode($result);
exit;