|
|
Zend_File_Transfer enables developers to take control over file uploads and also over file
downloads. It allows you to use built in validators for file purposes and gives you the ability even to
change files with filters. Zend_File_Transfer works with adapters which allow to use the
same API for different transport protocols like HTTP, FTP, WEBDAV and more.
Note: Limitation
The current implementation of
Zend_File_Transfershipped in 1.6.0 is limited to HTTP Post Uploads. Download of files and other Adapters will be added in the next releases. Also there is actually no filter available and the functionallity for it is not implemented. Not implemented methods will throw an exception. So actually you should use an instance ofZend_File_Transfer_Adapter_Httpdirectly. This will change in future, as soon as there are multiple adapters available.
The usage of Zend_File_Transfer is quite simple. It consist of two parts. The HTTP Form
which does the upload, and the handling of the uploaded files with Zend_File_Transfer.
See the following example:
Example #1 Simple File-Upload Form
This example illustrates a basic file upload which uses Zend_File_Transfer.
The first part is the file form. In our example there is one file which we want to upload.
Note that you should use Zend_Form_Element_File for your convenience instead of creating the HTML manually.
The next step is to create the receiver of the upload. In our example the receiver is
/file/upload. So next we will create the controller file
with the action upload.
$adapter = new Zend_File_Transfer_Adapter_Http();
$adapter->setDestination('C:\temp');
if (!$adapter->receive()) {
$messages = $adapter->getMessages();
echo implode("\n", $messages);
}
As you see the simplest usage is to define a destination with the setDestination
method and to call the receive() method. If there are any upload errors then you
will get them within an exception returned.
Note: Attention
Keep in mind that this is just the simplest usage. You should never just this example is an living environment as it causes severe security issues. You should always use validators to increase security.
|
|
Copyright © 2005-2011 Zend Technologies Inc (compiled by mikaelkael with ZFDocumentor - SVN 12849).

