views:

290

answers:

3

can any one suggest me the best way to write the code for uploading a file?
I need to upload file and save the file name in table. if the record saving is failed it should not upload the file.
If the uploading is failure then the record should be rollbacked.
The code should be reusable
I need to upload the file in afterSave callBack

+1  A: 

This is basic programming. If you're unsure, try Googling "php file upload" or "cakephp file upload".

Leo
i already googled.....got uploader component,helper etc
RSK
James Fairhurst is usually down to earth: http://www.jamesfairhurst.co.uk/posts/view/uploading_files_and_images_with_cakephp The W3Schools page will give you the basic understanding: http://www.w3schools.com/php/php_file_upload.asp and of course the PHP manual will tell you everything: http://www.php.net/manual/en/features.file-upload.post-method.phpIt's one of those things you just have to get to grips with. I wouldn't bother with a component or plugin. Just write your own and understand what it does and how.
Leo
+1  A: 

Take a look at the Cookbook too - File Fields.

bancer
+1  A: 

You might consider using the Media plugin that was talked about at the last CakeFest. It is fairly comprehensive, containing features such as creating file variations (ie. thumbnails of images or video), helpers for outputting different types of files, and elements to help create multiple-file upload forms more quickly; and also had a strong focus on security from the outset as I can gather from the slides (pdf or slideshare). I use it in production and find it works well, plus it seems to be under more active development than other options I have seen if that's anything to go by (eg. MeioUpload behavior, Uploader plugin, FileUpload plugin and various Bakery/blog posts on the topic).

deizel

related questions