Is cakephp support file upload without plugin? - cakephp

As the title, is cakephp support file upload without uses of plugin or not ?
**I means any code that made by cakephp developers not include pure php code.

Not really, for a full implementation you will need a plugin or create your own logic. Cake does offer convenience methods based on the base PHP functions. The File & Folder utility is an example.

You can use component instead of plugin like this one and it should do the job, but I'm not sure is this what you are looking for.

OK, Cakephp is support file upload, I just have to set the name of form to use it.

Related

yii importing file with functions

I have file with functions which I want to use everywhere in my application.
In raw PHP the way to do it is to call them in each file by include or require.
Is there any simple way in Yii to call this file once and use it everywhere?
Second question is to call the same file and use it in a particular controller.
You can require this file in main config of your appllication for example, or in beforeAcition method of application base controller if you have it.
require_once dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'components/some_funcs.php';
maybe this could help you THE DEFINITIVE GUIDE TO YII.
Using 3rd-Party Libraries
Yii is carefully designed so that third-party libraries can be easily integrated to further extend Yii's functionalities. When using third-party libraries in a project, developers often encounter issues about class naming and file inclusion. Because all Yii classes are prefixed with letter C, it is less likely class naming issue would occur; and because Yii relies on SPL autoload to perform class file inclusion, it can play nicely with other libraries if they use the same autoloading feature or PHP include path to include class files.
Below we use an example to illustrate how to use the Zend_Search_Lucene component from the Zend framework in a Yii application.
First, we extract the Zend framework release file to a directory under protected/vendors, assuming protected is the application base directory. Verify that the file protected/vendors/Zend/Search/Lucene.php exists.
Second, at the beginning of a controller class file, insert the following lines:
Yii::import('application.vendors.*');
require_once('Zend/Search/Lucene.php');

ruby on rails, file upload and database

maybe it's a question already ask but i did not find a answer.
Hello all.
I'm new ruby on rails.
I'm using Ruby 1.9.3 and rails 3.0.5, i want to create a page to upload file (video) on the shared folder of the server and when the file is upload i want to save the name of the file on my database (SQLITE3).
After i want to use the of HTML5 to list all the video i have on an other page.
The structure look like : Home -> click on button upload file -> upload page file -> return home to see the video list.
If possible i want to make it hand made, no gems.
For now i have try something like mix : http://french.railstutorial.org/chapters/user-microposts#top and http://www.tutorialspoint.com/ruby-on-rails/rails-file-uploading.htm. But did not get anything so far the work.
Thank you for the help.
p.s. : sorry if my english is not really good.
There is a reason people use gems. They provide flexibility and simplicity into application. Gems is blessing and not using gems when you can is a total waste of time. As for this application, please consider Carrierwave gem. One was specifically designed for file uploads. Here is a railscast video on how to use it. I'm sure you'll find it pretty simple and awesome to use.
I think you can use paperclip gem to upload image.

Which file to customize request_handler.php

I need to create a custom function in request_handler.
Which file should I edit:
core\cake\libs\controller\components\request_handler.php
or
app\controllers\components\request_handler.php
I believe that core should be mantained has origin and all the changes should be made on app folder, is this right? Assuming it's correct, I should duplicate the file (from core to app) and add the functions I need or just create a new file with the new functions?
Thanks!
Which versuion of Cake is this? Seems like 1.3?
You should NOT edit the core under any circumstances. It is also not good to add a function to request_handler.
If you need this logic all over the application just implement it in the AppController's callback functions.

Using App::uses (instead of App::import) in a CakePHP 2.1 Plugin

I'm writing a small application in CakePHP 2.1, and I want to use Nick Baker's file upload plugin. I downloaded the cakephp2.0 branch (I know that isn't done yet), and placed it in my apps Plugin folder. I made some necessary modifications on it, but I'm curious what the right way is to replace those App::import function calls (at start of FileUploadComponent, FileUploadBehavior and FileUploadHelper classes) with the App:uses function.
It needs to import the FileUploadSettings class from Config/file_upload_settings.php and the Uploader class from Vendor/upload.php. It can be done with the require_once function, but I'm sure there is a CakePHP way to do it.
From what I've gathered:
use import() for external libraries
and uses() for framework files
For example:
App::import('Vendor', 'ExternalLibrary');
App::uses('Inflector', 'Cake.Utility');
According to the Cake manual App::import() is comparable to the way require_once() works. From what I understand you would load classes using App:uses() and Vendor files using App:import().
The API documentation says the following on the subject:
All classes that were loaded in the past using App::import(‘Core’, $class) will need to be loaded using App::uses() referring to the correct package. This change has provided large performance gains to the framework.
The method no longer looks for classes recursively, it strictly uses
the values for the paths defined in App::build()
It will not be able to load App::import('Component', 'Component') use App::uses('Component', 'Controller');.
Using App::import('Lib', 'CoreClass'); to load core classes is no longer possible. Importing a non-existent file, supplying a wrong type or package name, or null values for $name and $file parameters will result in a false return value.
App::import('Core', 'CoreClass') is no longer supported, use App::uses() instead and let the class autoloading do the rest.
Loading Vendor files does not look recursively in the vendors folder, it will also not convert the file to underscored anymore as it did in the past.
The migration guide also has some things to say about App:uses() and is a good starting point in general to compare best practices for 2.0 with the older methods from 1.3 and lower.
This related question deals with loading Vendor files in Cake 2.0, I can't verify the claim by José Lorenzo that App:import() is a "silly wrapper" for require_once(), nor the statement that it's the preferred way of including files. The only reference I could find for the latter is in the Coding Standards for Cake contributors, viz. developers contributing to the Cake core, not applications built on the framework.
EDIT
Let's say you want to import the Twitter OAuth library, residing in Vendor/twitter, the main class file is twitteroauth.php in Vendor/twitter/twitteroauth/twitteroauth.php:
App::import('Vendor', 'twitteroauth', array('file' => 'twitter'.DS.'twitteroauth'.DS.'twitteroauth.php'));

Cakephp: Include php script in .ctp file

I want to add captcha in myfile.ctp. For this i found source for captcha along with some resource files includs(js, php).
I know the folder for js files & include this file using <?php echo $javascript->link(array('ajax_captcha.js'));?>. But I don't know where to place .php file &
also how to include it in myfile.ctp
Or if anybody help me to implement Captcha in Cakephp.
For your js, use $javascript->link('ajax_captcha',false); Not the omission of the extension. false will place it in the section of the HTML. This will look for the script in webroot/js
Personally, I would just use a standard php include directive for the php side of things, bearing in mind that the location will be relative to webroot, i.e. '/myPHP/captcha.php'will be webroot/myPHP/captcha.php.
Don't forget, CakePHP is PHP.
I'd use a plugin or component, http://bakery.cakephp.org/articles/view/captcha-component-with-phpcaptcha
This works very well with PHPCaptcha for all your Human vs Computer shenanigans. Feel free to google around for your preferred plugin/component.
There is another article in the bakery - Integrate CakePHP with Kcaptcha (read the comments there too). I have successfully implemented kcaptcha in my application.
Elements are a good way to pull code that gets sprinkled over and over around various views:
http://book.cakephp.org/2.0/en/views.html#elements

Resources