0

我正在尝试使用 rename-addFilter 重命名上传的文件。实际上传已经可以了,但是文件只是上传并没有重命名,那么我该怎么做呢?这是我的控制器代码,用于上传文件:

        //Getting the new filename, works perfectly:
        $name = explode('.', $form['pic']);
        $ext = $name[1];
        $mapper = new Application_Model_CmsMap();
        $row = $mapper->fetchRow('childId = "' . $id . '" AND type= "pic"');
        $new_filename = $row->name.'.'.$ext;

        //All images will and are be stored in /public/images/
        //Maybe the picture should be replaced, so it should be overwrited, in case it already exists
        $upload->addFilter('Rename', array(
            'target' => '/images/'.$new_filename,
            'overwrite' => true,
            )
        );

        $upload->receive();
4

2 回答 2

2

拧禅。好的 ol' PHP 很简单并且可以完美运行:

rename('images/'.$form['pic'], 'images/'.$new_filename);
于 2012-06-21T14:17:06.747 回答
0

应该管用 :-)

    $transferAdapter = new Zend_File_Transfer_Adapter_Http();
    $transferAdapter->receive();

    $newFilename = 'MY_NEW_FILE';

    $filterFileRename = new Zend_Filter_File_Rename(array(
        'target'    => 'PATH' + $newFilename,
    ));

    $file = $transferAdapter->getFileName();

    // new location and name..
    $movedFile = $filterFileRename->filter($file);
于 2012-06-21T16:45:10.273 回答