SWFUpload Component

May 20, 2007 at 3:50 pm 9 comments

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.’);
$this->SwfUpload->deleteRecentUpload();
}

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

Entry filed under: cakephp, components.

Security components in cakephp

9 Comments Add your own

  • 1. james revillini  |  June 15, 2007 at 2:58 pm

    This is tight. I really like the improvements. I’ll definitely grab this to use as my platform for the next release. I’m glad my software gave you the starting point you needed. I haven’t been over to the SWFUpload site in awhile so I have to go read up on what’s new with the uploader itself. Peace!

    Reply
  • 2. Robert  |  January 17, 2008 at 3:13 am

    When I try to set the uploadpath var from my controller it does not work. For example:

    $this->SwfUpload->uploadpath = ‘/var/www/app/webroot/uploads/’

    If I set the $uploadpath variable directly in the component it seems to work. The only problem with that is if you want to have different upload directories depending on where you are calling the component from.

    I am missing something simple here? Thanks for your help and some great additions to a great component.

    Reply
  • 3. rdeman  |  April 1, 2008 at 11:13 am

    what about CakePHP V1.2 and SWFUpload V2.x ?
    It moved to http://swfupload.org/project
    your component was great fo rthe old SWFuplaod and CakePHP v1.1…. any updates?

    Reply
  • 4. ouch  |  June 2, 2008 at 11:21 pm

    Ouch says : I absolutely agree with this !

    Reply
  • 5. Despondent  |  June 19, 2008 at 2:09 pm

    Somehow i missed the point. Probably lost in translation 🙂 Anyway … nice blog to visit.

    cheers, Despondent

    Reply
  • 6. Michael  |  April 3, 2010 at 1:34 pm

    Hi,

    Before I dive into the Code can you tell me if this will work for Cake 1.2?

    Thanks,
    Michael

    Reply
  • 7. Amjith  |  June 28, 2010 at 10:58 pm

    y there is no updates/?

    Reply
  • 8. dpriestwp  |  July 20, 2011 at 8:40 am

    why i always get the alert windows of the source code of index file.

    Reply
  • 9. chenfuller60210  |  April 8, 2016 at 2:08 pm

    Hallo Princo , hoooohhhooohoooo gerne wu00e4re ich auch dabei … ich shiess mir bestimmt kein auge aus …. Danke fu00fcr den Link …. Click https://twitter.com/moooker1

    Reply

Leave a reply to Robert Cancel reply

Trackback this post  |  Subscribe to the comments via RSS Feed


Recent Posts

May 2007
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031