RSS

Category Archives: ZF

Renaming file name in the file uploading process in ZF

The following code works for me to rename a file name in the uploading process in zend framework.


$fileTransferObject = new Zend_File_Transfer_Adapter_Http();
$uploadDir = 'your_upload_directory';

$fileTransferObject->setDestination($uploadDir);

$renameFilter = new Zend_Filter_File_Rename( $uploadDir );
$files = $fileTransferObject->getFileInfo();
$time = microtime();
$timeArray = explode(‘ ‘ , $time);
$timeStr = $timeArray[1];
foreach($files as $fileID => $fileInfo)
{
if(!$fileInfo[‘name’]==”)
{
$renameFilter->addFile( array(‘source’ => $fileInfo[‘tmp_name’], ‘target’ => $timeStr.’_’.$fileInfo[‘name’], ‘overwrite’ => true ) );
}
}
$fileTransferObject->addFilter($renameFilter);
//check file recieved successful.
if (!$fileTransferObject->receive()) {
$messages = $fileTransferObject->getMessages();
}

Advertisements
 
Leave a comment

Posted by on August 8, 2011 in ZF

 

Tags: , ,