PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Rename filter

The Rename filter allows to change the destination of the upload, the filename and also to overwrite existing files. It supports the following options:

  • source: The name and destination of the old file which shall be renamed.

  • target: The new directory, or filename of the file.

  • overwrite: Sets if the old file overwrites the new one if it already exists. The default value is FALSE.

Additionally you can also use the method setFile() to set files, which erases all previous set, addFile() to add a new file to existing ones, and getFile() to get all actually set files. To simplify things, this filter understands several notations and that methods and constructor understand the same notations.

Example 436. Using the Rename filter

<?php
$upload 
= new Zend_File_Transfer_Adapter_Http();

// Set a new destination path for all files
$upload->addFilter('Rename''C:\mypics\new');

// Set a new destination path only for uploadfile1
$upload->addFilter('Rename''C:\mypics\newgifs''uploadfile1');

You can use different notations. Below is a table where you will find a description and the intention for the supported notations. Note that when you use the Adapter or the Form Element you will not be able to use all described notations.

Table 75. Different notations of the rename filter and their meaning

notation description
addFile('C:\uploads') Specifies a new location for all files when the given string is a directory. Note that you will get an exception when the file already exists, see the overwriting parameter.
addFile('C:\uploads\file.ext') Specifies a new location and filename for all files when the given string is not detected as directory. Note that you will get an exception when the file already exists, see the overwriting parameter.
addFile(array('C:\uploads\file.ext', 'overwrite' => true)) Specifies a new location and filename for all files when the given string is not detected as directory and overwrites an existing file with the same target name. Note, that you will get no notification that a file was overwritten.
addFile(array('source' => 'C:\temp\uploads', 'target' => 'C:\uploads')) Specifies a new location for all files in the old location when the given strings are detected as directory. Note that you will get an exception when the file already exists, see the overwriting parameter.
addFile(array('source' => 'C:\temp\uploads', 'target' => 'C:\uploads', 'overwrite' => true)) Specifies a new location for all files in the old location when the given strings are detected as directory and overwrites and existing file with the same target name. Note, that you will get no notification that a file was overwritten.

Zend Framework