Archive for May, 2007

SWFUpload Component

I have been looking for this kind of component for a while and it just deals almost everything that I wanted for in an uploader component. For more details about this component, you may check James Revillini’s website, the author of the component, and/or the bakery. I also found his kit very useful. The kit is for multiple uploads and I already liked the design. I haven’t had the time to change the layout though. As for the changes that I mentioned, here is the list:

  • applied the suggestions of Matthias Willerich, I will also use this component for my non-swfuploader forms so I wanted it to be independent to the structure..
  • added mime type validation, I got the idea from Chris Partridge’s File Handler component but now I couldn’t find the link in cakeForge. Basically, it checks if the uploaded file is an accepted one. This is not mandatory so you can leave the checking if you don’t want to. Sample codes below.
  • added the function deleteRecentUpload() to be able to easily delete the image once the processing database was not successful.
  • added the option to choose the renaming scheme. Sometimes I need to rename the file to random characters. You can set the var $random_word_length to change the number of characters generated. You can choose a partial or full change or random characters by changing the var $filenameType. Values accepted are default, full or partial. When I say partial, the original filename will have a prefix of random characters. You can have your own renaming scheme too, check the findRandomFilename().

A snippet from my controller

if ($this->SwfUpload->upload($this->data[‘Upload’][‘image’], array(‘img’))) {
$this->data[‘Upload’][‘image’] = $this->SwfUpload->filename;
} else {
$this->set(‘error’, $this->SwfUpload->errorMessage);
if (!$this->Upload->save($this->data)){
$this->set(‘error’, ‘Unable to complete request.’);

The array('img') is the mime type checking.You can leave it null so the component won’t check that part or you may pass as many values as you want.

$this->SwfUpload->deleteRecentUpload() deletes the last image uploaded.

I hope I explained myself better and the component will also be useful to others.

Download the code here


May 20, 2007 at 3:50 pm 9 comments

Security components in cakephp

I started following cakePhp since it’s .10 version and at those times the manual do not have enough to tell us about how it handles security. Luckily today, I paused work  to read “how to use the Sanitize and Security components” from IBM and I was glad I took the time. Security is really a must have in every form submission and gladly, cakePhp developers knows that and brought us simple ways to handle them. It is not the ultra easy way to do it, as developers, we still have to do something on our own but this is already a great stuff to lessen the workload, I hope.. The manual has been updated, i don’t know when since it’s been a long time when I last visited it, so you might also want to check that.

May 16, 2007 at 9:26 am 2 comments

Recent Posts

May 2007
« Apr