{"id":17268153,"url":"https://github.com/tute/thumbnail-component-for-cakephp","last_synced_at":"2026-02-28T10:06:56.320Z","repository":{"id":607812,"uuid":"244901","full_name":"tute/Thumbnail-component-for-CakePHP","owner":"tute","description":"A file uploader and thumbnailer component for CakePHP 1.3 and 2.","archived":false,"fork":false,"pushed_at":"2016-09-01T11:13:46.000Z","size":1511,"stargazers_count":80,"open_issues_count":2,"forks_count":13,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-14T08:41:34.599Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"conformal/gotk3","license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tute.png","metadata":{"files":{"readme":"README.textile","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2009-07-07T03:04:21.000Z","updated_at":"2022-06-24T10:09:55.000Z","dependencies_parsed_at":"2022-07-07T14:59:31.838Z","dependency_job_id":null,"html_url":"https://github.com/tute/Thumbnail-component-for-CakePHP","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/tute/Thumbnail-component-for-CakePHP","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tute%2FThumbnail-component-for-CakePHP","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tute%2FThumbnail-component-for-CakePHP/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tute%2FThumbnail-component-for-CakePHP/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tute%2FThumbnail-component-for-CakePHP/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tute","download_url":"https://codeload.github.com/tute/Thumbnail-component-for-CakePHP/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tute%2FThumbnail-component-for-CakePHP/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29929681,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-28T09:58:13.507Z","status":"ssl_error","status_checked_at":"2026-02-28T09:57:57.047Z","response_time":90,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-15T08:12:38.125Z","updated_at":"2026-02-28T10:06:56.302Z","avatar_url":"https://github.com/tute.png","language":"PHP","readme":"*Attachment component for CakePHP* handles file uploads to the file system. If\r\nit's an image file, it creates thumbnail copies in\r\n@/app/webroot/attachments/photos/{required_sizes}@ folder; while other files\r\nare stored in @/app/webroot/attachments/files@.\r\n\r\nI've started it from the public copy at\r\n\"@http://sabbour.wordpress.com/2008/07/18/enhanced-image-upload-component-for-cakephp-12/@\":http://sabbour.wordpress.com/2008/07/18/enhanced-image-upload-component-for-cakephp-12/\r\nto have a standard way of uploading files to CakePHP projects.\r\n\r\nSee branch cake1.3 for Cake 1.3 version; branch cake2 for CakePHP 2 version.\r\n\r\nh2. Requirements\r\n\r\n# PHP GD library installed and enabled.\r\n# @/app/webroot/attachments/@ must be writable by the web server.\r\n\r\nh2. Installation\r\n\r\n# Copy @attachment.php@ to @/app/controllers/components/@\r\n# Add component to your controller: @var $components = array('Attachment');@\r\n# Add DB columns {prefix}_file_path, {prefix}_file_name, {prefix}_file_size\r\nand {prefix}_content_type to the model. The prefix is the model name, in\r\nlowercase, words seperated by underscores.\r\n\r\nh2. Model setup\r\n\r\nWe'll asume a Model named 'Pet' for a sample installation. The code relies on\r\nfour columns in the Model table:\r\n\r\n@pet_file_path, pet_file_name, pet_file_size@ and @pet_content_type@\r\n\r\nModels with multi-word names should have each word seperated by underscores.\r\nFor example, the model \"GalleryPhoto\" would use the table \"gallery_photos\" and\r\nthe following fields:\r\n\r\n@gallery_photo_file_path, gallery_photo_file_name, gallery_photo_file_size@ and @gallery_photo_content_type@\r\n\r\nThese fields are automagically updated when you call @save()@ on the @$this-\u003edata@ array\r\n\r\nh2. View setup\r\n\r\nh3. On forms\r\n\r\n@\u003c?= $this-\u003eForm-\u003ecreate('Pet', array('type' =\u003e 'file'));@\r\n@\u003c?= $this-\u003eForm-\u003einput('pet' , array('type' =\u003e 'file')); ?\u003e@\r\n@\u003c?= $this-\u003eForm-\u003eend('Save my pooch'); ?\u003e@\r\n\r\nThe (file) input 'pet' is the lower case model-name, multi-word model names\r\nseperated by underscores.\r\n\r\nh3. Show files (after they are saved)\r\n\r\nFor images: @\u003c?= $this-\u003eHtml-\u003eimage('/attachments/files_dir/{size}/' . $data['Pet']['pet_file_path']); ?\u003e@\r\nFor files:  @\u003c?= $this-\u003eHtml-\u003elink('Grab file', '/attachments/files_dir/' . $data['Pet']['pet_file_path']); ?\u003e@\r\n\r\nh2. Controller setup\r\n\r\nConfiguration options (default values between parentheses):\r\n\r\n* @files_dir@: Where to save the files (inside @/app/webroot/attachments/@) (@photos@).\r\n* @rm_tmp_file@: Remove temporal image after resizing (@false@).\r\n* @allow_non_image_files@, self descriptive ;-) (@true@).\r\n* @default_col@: Column prefix for file related data (lowercase modelname, words seperated by underscores).\r\n* @images_size@: Array of different file sizes required by your app. Each\r\n  element is itself an array, like: @'folder_name' =\u003e array($width, $height, $crop)@.\r\n  (You may define only width or height, and the image will scale appropriately).\r\n\r\nYou can override the default configuration passing an array of options while\r\nincluding the component, like:\r\n\r\n@var $components = array('Attachment' =\u003e array(\r\n\t'files_dir' =\u003e 'pets',\r\n\t'images_size' =\u003e array(\r\n\t\t'avatar'  =\u003e array(75, 75, 'resizeCrop')\r\n\t)\r\n));@\r\n\r\nh3. Controller methods:\r\n\r\nh4. upload($data)\r\n\r\n* @data@: Raw data from form.\r\n\r\nSimply call the following on the form data:\r\n\r\n@$this-\u003eAttachment-\u003eupload($this-\u003edata['Pet']);@\r\n\r\nYou may choose different column prefixes than the model name, as long as you\r\nspecify it on the upload method, like so:\r\n\r\n@$this-\u003eAttachment-\u003eupload($this-\u003edata['Pet'], 'dog');@\r\n\r\nh4. thumbnail($data, $upload_dir, $maxw, $maxh, $crop = 'resize')\r\n\r\nUsed by the more general @upload@ method.\r\n\r\n* @data@: image data array\r\n* @upload_dir@: where to save the file (inside @attachments/files_dir@)\r\n* @maxw/maxh@: maximum width/height for resizing images\r\n* @crop@: Crop image? (one of @resize@, @resizeCrop@ or @crop@)\r\n\r\nh4. delete_files($filename)\r\n\r\n* @filename@: file-to-delete name\r\n\r\nh2. Validations\r\n\r\nYou may wish to validate from the model. e.g:\r\n\r\n@var $validate = array(@\r\n\t\t@'pet_file_size' =\u003e array(@\r\n\t\t\t@'rule' =\u003e array('maxLength', 6),@\r\n\t\t\t@'message' =\u003e 'Image size is waaaaaayyy too big. Try resizing first'@\r\n\t\t\t@)@\r\n\t @);@\r\n\r\nh3. Show validation errors in the view\r\n\r\n@if(isset($this-\u003eForm-\u003evalidationErrors)) {@\r\n  @foreach ($this-\u003eForm-\u003evalidationErrors as $model =\u003e $columns) {@\r\n    @foreach ($columns as $err_msg) {@\r\n      @echo $this-\u003eHtml-\u003ediv('error-message', $err_msg);@\r\n    @}@\r\n  @}@\r\n@}@\r\n\r\nh4. Only for the file input:\r\n\r\n@if (isset($this-\u003eForm-\u003evalidationErrors['Pet']['pet_file_name'])) {@\r\n\t@echo $this-\u003eHtml-\u003ediv('error-message', $this-\u003eForm-\u003evalidationErrors['Pet']['pet_file_name']);@\r\n@}@\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftute%2Fthumbnail-component-for-cakephp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftute%2Fthumbnail-component-for-cakephp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftute%2Fthumbnail-component-for-cakephp/lists"}