Re: Saving data in a component class
nope i didnt...if thats what it takes ill give it a try. thx a lot :) On 12 Jul., 10:52, nini 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 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
Re: Saving data in a component class
".print_r($this->data,true).""; if(!empty($this->data)){ echo "".print_r($this->data,true).""; 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','successfully saved'); } } } else{ $this->set('userMessage', 'Image cannot be empty'); } } } } ?> On Mon, Jul 12, 2010 at 2:22 PM, nini 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 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'][
Re: Saving data in a component class
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 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) { >
Saving data in a component class
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); }