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 For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to