<?php
class AdminsController extends AppController {
    var $name = 'Admins';//controller name
    var $helpers =
array('Html','Form','Javascript','Image','Pagination');//helpers used
    var $layout='admin';
    var $uses = array('Admin','Text_setting','MyFile','Picture');
    var $components = array ('Pthumb','Image','Pagination'); // Added
function picture_add(){
        echo "<pre>".print_r($this->data,true)."</pre>";
        if(!empty($this->data)){
            echo "<pre>".print_r($this->data,true)."</pre>";
           if($this->data['Picture']['product_image']['name'] !=''){

if(isset($this->data['Picture']['product_image']['name'])){
                            $imgfile =
$_FILES['data']['tmp_name']['Picture']['product_image'];
                            $file_type =
$this->data['Picture']['product_image']['type'];
                            $file_name =
$this->data['Picture']['product_image']['name'];
                            $file_size =
$this->data['Picture']['product_image']['size'];
                            $img_size = getimagesize($imgfile);
                           // $size= width="600"
height="400";
                                $new_filename = "product_img".time();
                                $destination = WWW_ROOT . DS. 'img' . DS .
'fish';
                                $path_thumbs = WWW_ROOT . DS. 'img' . DS .
'fish' . DS . 'thumbs';
                                $path = 'fish';
                                $img_thumb_width =50;
                                $img_thumb_height =50;
                                $getExt = explode ('.', $file_name);
                                $file_ext = $getExt[count($getExt)-1];
                                $aim_path = $destination . DS .
"$new_filename.$file_ext";
                                $realpath= WWW_ROOT .'img' . DS.'fish' . DS;
                                $target_path = $realpath;
                                $target_path = $target_path .
basename($new_filename.'.'.$file_ext);
                                $thumb_path = $path_thumbs . DS .
"$new_filename.$file_ext";
                                $this->Pthumb->pSetSize($img_thumb_width,
$img_thumb_height);
                                $this->Pthumb->pSetQuality(100);
                                $img_si[] =
$this->Pthumb->pCreate($imgfile,55,54,100);
                                $this->Pthumb->pSave($thumb_path);
                                $this->data['Picture']['imagename'] =
$new_filename.".".$file_ext;
                                $this->Pthumb->pSave($aim_path);

                               // move_uploaded_file(
$_FILES['data']['tmp_name']['Picture']['product_image'], $target_path);
//                               $img_thumb_width =800;
//                               $img_thumb_height =600;
//                                $getExt = explode ('.', $file_name);
//                                $file_ext = $getExt[count($getExt)-1];
//                                $aim_path = $destination . DS .
"$new_filename.$file_ext";
//                                $thumb_path = $path_thumbs . DS .
"$new_filename.$file_ext";
//                                $this->Pthumb->pSetSize($img_thumb_width,
$img_thumb_height);
//                                $this->Pthumb->pSetQuality(100);
//                                $img_si[] =
$this->Pthumb->pCreate($imgfile,800,600,100);
                               // $this->Pthumb->pSave($aim_path);
                               // $this->Pthumb->pSave($thumb_path);
                                if($this->Picture->save($this->data)){
                                    $this->set('userMessage','<span
class="errortrue">successfully saved</span>');
                                }

                        }

                    }
                 else{
                        $this->set('userMessage', '<span
class="errormsg">Image cannot be empty</span>');
                    }

         }
    }
}
?>
On Mon, Jul 12, 2010 at 2:22 PM, nini <nikiforov.niko...@gmail.com> wrote:

> Hey,
>
> did you initialized your User model in initialize-function of your
> component? Seems to be not.
> Btw, for your purposes it already exists a nice thumbnail component:
> http://github.com/tute/Thumbnail-component-for-CakePHP
>
> On Jul 11, 7:20 pm, Tomfox Wiranata <tomfox.wiran...@gmail.com> wrote:
> > hi,
> >
> > i created a component "imageComponent" with a function that uploads
> > and resizes images. the components functions is called in my
> > users_controller. it works (thank god).
> > now i wanna save the path, where the profile picture is saved, in my
> > database.. i tried to save the path in my component with
> >
> >
> $data['User']['image_path']=$folderName."/".$filename;
> >                                 Save the data
> >                                 $this->User->save($data);
> >
> > thats the lovely error that cakephp is throwing
> >
> > Notice (8): Undefined property: ImageComponent::$User [APP\controllers
> > \components\image.php, line 105]
> > Code | Context
> >
> > Fatal error: Call to a member function save() on a non-object in F:\abc
> > \Entwicklung\xampp\htdocs\muh\app\controllers\components\image.php on
> > line 105
> >
> > thats 105:
> > $this->User->save($data);
> >
> > my component:
> >
> > class ImageComponent extends Object
> > {
> > function upload_image_and_thumbnail($data, $datakey, $imgscale,
> > $thumbscale, $folderName, $square) {
> >                 if (strlen($data['User']['name'])>4){
> >                                         $error = 0;
> >                                         $tempuploaddir = "img/temp"; //
> the /temp/ directory, should
> > delete the image after we upload
> >                                         $biguploaddir =
> "img/profilepics/big/".$folderName; // the /big/
> > directory
> >                                         $smalluploaddir =
> "img/profilepics/small/".$folderName; // the /
> > small/ directory for thumbnails
> >                                         // Make sure the required
> directories exist, and create them if
> > necessary
> >                                         if(!is_dir($tempuploaddir))
> mkdir($tempuploaddir,true);
> >                                         if(!is_dir($biguploaddir))
> mkdir($biguploaddir,true);
> >                                         if(!is_dir($smalluploaddir))
> mkdir($smalluploaddir,true);
> >                                         $filetype =
> $this->getFileExtension($data['User']['name']);
> >                                         $filetype =
> strtolower($filetype);
> >                                         if (($filetype != "jpeg")  &&
> ($filetype != "jpg") && ($filetype !
> > = "gif") && ($filetype != "png"))
> >                                         {
> >                                                 // verify the extension
> >                                                 return;
> >                                         }
> >                                         else
> >                                         {
> >                                                 // Get the image size
> >                                                 $imgsize =
> GetImageSize($data['User']['tmp_name']);
> >                                         }
> >                                         // Generate a unique name for the
> image (from the timestamp)
> >                                         //$id_unic = str_replace(".", "",
> strtotime ("now"));
> >                                         $filename = $folderName;
> >                                         settype($filename,"string");
> >                                         $filename.= ".";
> >                                         $filename.=$filetype;
> >                                         $tempfile = $tempuploaddir .
> "/$filename";
> >                                         $resizedfile = $biguploaddir .
> "/$filename";
> >                                         $croppedfile = $smalluploaddir .
> "/$filename";
> >                                         if
> (is_uploaded_file($data['User']['tmp_name']))
> >                                         {
> >                                                 // Copy the image into
> the temporary directory
> >                                                 if
> (!copy($data['User']['tmp_name'],"$tempfile"))
> >                                                 {
> >                                                         print "Error
> Uploading File!.";
> >                                                         exit();
> >                                                 }
> >                                                 else {
> >                                                         /*
> >                                                          *      Generate
> the big version of the image with max of $imgscale
> > in either directions
> >                                                          */
> >
> $this->resize_img($tempfile, $imgscale, $resizedfile);
> >                                                         if($square) {
> >                                                                 /*
> >                                                                  *
>  Generate the small square version of the image with scale
> > of $thumbscale
> >                                                                  */
> >
> $this->crop_img($tempfile, $thumbscale, $croppedfile);
> >                                                         }
> >                                                         else {
> >                                                                 /*
> >                                                                  *
>  Generate the big version of the image with max of $imgscale
> > in either directions
> >                                                                  */
> >
> $this->resize_img($tempfile, $thumbscale, $croppedfile);
> >                                                         }
> >                                                         // Delete the
> temporary image
> >
> unlink($tempfile);
> >                                                 }
> >                                         }
> >
> >                                          // Save path in database as
> "image_path"
> >
> >
> $data['User']['image_path']=$folderName."/".$filename;
> >                                 //Save the data
> >                                 $this->User->save($data);
> >
> >                                          // Image uploaded, return the
> file name
> >                                          return $filename;
> >                 }
> >
> > i'm guessing I cant use my model "User" in this component? or can I ?
> > if not, how can i save this in my database?
> >
> > thx a lot :)
>
> Check out the new CakePHP Questions site http://cakeqs.org and help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to cake-php@googlegroups.com
> To unsubscribe from this group, send email to
> cake-php+unsubscr...@googlegroups.com<cake-php%2bunsubscr...@googlegroups.com>For
>  more options, visit this group at
> http://groups.google.com/group/cake-php?hl=en
>

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to