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.’);
$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

May 20, 2007 at 3:50 pm 8 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

Internet in your toilet!

Had it ever came to your mind that you can have FREE internet thru your toilet? hehe.. this one is really something .. uhm.. weird?

 MOUNTAIN VIEW, Calif., April 1, 2007 – Google Inc. (NASDAQ: GOOG) today announced the launch of Google TiSP (BETA)™, a free in-home wireless broadband service that delivers online connectivity via users’ plumbing systems. The Toilet Internet Service Provider (TiSP) project is a self-installed, ad-supported online service that will be offered entirely free to any consumer with a WiFi-capable PC and a toilet connected to a local municipal sewage system.

 Read more.. I wish it would also become available other than US and Canada.. I want to try it!!

April 2, 2007 at 2:33 am Leave a comment

Things you should know about cakePhp

21 things I learned about cakePhp almost covers all the basics to intermediate lessons a beginner should know about.. check them one by one and you’ll surely get some good points even if you have used it for a long time. I did and got a lot of new lessons!

I have some more things to add or comment to.

Easily creating static pages
This is a great solution! if you want to rename it, you can use the route.php to configure the names. example, i have an about page, you can point http://www.example.com/pages/about to http://www.example.com/about.. quite neat. Read this tutorial for more options on how to do it.

Viewing the SQL queries that are running behind the scenes
I use this code to hide and unhide those sql queries (which i really love)

Multiple sources of documentation
Add the bakery to that. More resources here.

Using bake.php
Do try this one, you’ll surely love cakePhp more..

Mind permissions when moving cake around
This is one of the most common error
Warning: file_put_contents(/home/directory/app/tmp/cache/models/default_gcsbox_list) [function.file-put-contents]: failed to open stream: Permission denied in /home/directory/cake/basics.php on line 822

Just do the chmod -R 777 to /app/tmp as suggested.

Creating a controller that uses other models
I use this most of the time but you should also not forget that you can use the $this->Post->User->function();

There is another method where you can use another model in the Model class but can’t find that link yet.. I will update this once i found it.

Call exit() after redirecting
if you are using cakePhp1.2, you do the ffg:

$this->redirect('controller/action', null, true);

According to this post, the latter makes the app testable than using the exit or return. Return would also be a good option but be careful when using it in the beforeFilter(). Read more here.
Some more additional info

  1. Use debug() to display an array covered by the pre tag so you can check the array clearly.
  2. bindModel and unbindModel on the fly. I also found this code very helpful and provide cleaner interface for the controllers

I also notice among my friends that uses xampp, after the installation, the sample page has a very basic html look. You should atleast see the colors of the cakePhp main site to know its really working (aside from the database message). If you experienced this problem, check your Apache configuration. My conf has the ffg codes

<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>

I just change the AllowOverride None to AllowOverride All and things work perfectly.

If you have common things you use that you want to share, please inform me and I’ll be happy to add them to the list..

March 28, 2007 at 3:51 pm 10 comments

A question of ‘to bake or not to bake’

This question stucked me for some time now.. I even googled the question why use a framework before. (My framework of choice is MVC and cakePhp, so this will talk about the 2.)

There are many debates in determining if you need/want a framework or not. Here’s the opinion of Rasmus about MVC.

I don’t have much of a problem with MVC itself. It’s the framework baggage that usually comes along with it that I avoid. Parts of frameworks can be useful as long as you can separate the parts out that you need. As for MVC, if you use it carefully, it can be useful in a web application. Just make sure you avoid the temptation of creating a single monolithic controller.

It’s a matter of personal perspective in development, how well can you learn the framework in time and how patient are you to master this new tool to be able to use it wisely. As for me, I remember that I came to a point that I was so upset because I can’t do what I want. There are just so many things that I think are not useful and not possible in a framework. I like the simple call to query, I like the helpers a lot, I like the debugging tools, I like and dont like the foldering system, I like the team and the community who are very helpful at many times, I like the URL setup, I like and dont like the HABTM, I don’t like the documentation, etc. etc.. There are so many things that I like and don’t like just because they are new to me or they are hard to understand. But that’s how frameworks are, they teach you of something else out of your system. You may or may not like it at first but you’ll eventually learn and appreciate it. I didn’t like php at first because I have to learn a NEW environment again (I was a VB developer then, became a Mediawiki hacker(sort of)).

One important aspect that I liked in a framework, it guides you in a way everybody in your team will also follow. I am not the boss in our group so I can’t tell everyone that ‘hey, you should do this and that to make things clearer for me’ (in simple words, to please me and make my programming life easier). Rather, the framework tells us what to do and how to organize things. It is our manager. Eventhough frameworks acts like that, it should not limit you to do your job. I’ve learned from one of the cakephp team that once it makes your life harder, then just do it the way it’s easier. Frameworks should make our life easier, not the other way round. So today, I am not stucked to make it all ‘cakish’ unlike before when I was starting. As long as it works and it doesnt break anything especially the core, then I have no problem. I am still using php as my language and I should code like I used to be. To quote Rasmus, php always tries to find the shortest path to solving the Web problem, so cakePhp shouldn’t be a hindrance to that.

Again, frameworks should work as guidelines, not rules. Use it, dont make it use you. If you can do it in a better way, then just do it! If it doesnt help, move on and try something else. I am not stucked with how cakePhp should do it specially that it really lacks documentation right now. I’ll learn it on the way, while improving myself and my abilities in using it. As for now, just do it. (I am not a Nike fan, i read this in a blog before but can’t remember the url. I just love that line ;) )

I’ll leave you with another perspective of another baker:

After these experiences with two different applications using cake, I guess it’s not a question of when or when not to bake, but rather, how you would actually do the baking. You can always bake, complex application or not, you just have to have a well studied and structured approach on how to bake your cake :) .

March 15, 2007 at 11:24 am Leave a comment

Anime on your desktop

Do you like anime? If you do, then you might like this one. It’s the MaCoPiX (Mascot Constructive Pilot for X) desktop mascot application on UNIX / X Window system. Primarily I just like the windows sitter, it gives life to my linux os. But there are also other special features, check below:

  • You can make window sitters , fixed desktop mascots, and, furthermore, desktop clock mascots, using MaCoPiX. This application could be a follower of “ActX”. So, it is basically put emphasis on the function as an window sitter. But, of course, it can be used as the other type of desktop mascots.
  • Using Gtk+ as GUI. MaCoPiX can edit its all configuration from its GUI. Furthermore, it is possible to create any mascots. You don’t need to use any text editors for such purposes.
  • Using gdk-pixbuf for image loading. Compared with ActX, in which we can only use xpm type imgaes, MaCoPiX can handle all types of images supported by gdk-pixbuf.

Here is a view of my browser with macopix:

mascot on browser

Here’s a larger view.

Pretty cool toy for my ubuntu desktop ;) There’s quite a lot of characters to choose from although right now they are all females.

What also interest me is that you can also create your own animation, though not now. The how-to page is still under construction but I am looking forward to it.

Have fun anime-fans-alike!

February 28, 2007 at 10:25 am 4 comments

Time to upgrade

news.. new.. news..  need to updrade now..

A kind soul informed us that the Not Found error page can be exploited via inserting javascript code in the address bar. This release provides a fix for this vulnerability. This release also includes some other improvements to the bake script and prepares for the day when the controller object is not available in the view. Cakebaker mentioned the addition of the session helper. It is recommended that everyone upgrade and change all references to $this->controller->Session in the view to the new helper, $session.

October 1, 2006 at 11:34 am Leave a comment

Older Posts


Recent Posts

April 2014
M T W T F S S
« May    
 123456
78910111213
14151617181920
21222324252627
282930  

Follow

Get every new post delivered to your Inbox.