简体   繁体   中英

File 'C:\xampp\tmp\php3226.tmp' could not be renamed. It already exists error in zend, how to?

i am using this function to upload files to the disk:

$talentFolderPath = 'C:/xampp/htdocs/project/';

public function uploadToDisk($talentFolderPath, $filename)
{

    $adapter = new Zend_File_Transfer_Adapter_Http();
    $adapter->setDestination($talentFolderPath);
    $adapter->addFilter( 'Rename',array('target' => $talentFolderPath."/".$filename) );
    if ($adapter->receive()) {
        $message = "success";
    } else {
        $message = "fail";
    }

    return $message;
}

and i get this message:

Message: File 'C:\\xampp\\tmp\\php3226.tmp' could not be renamed. It already exists.

Any ideas what is going on?

Thanks.

The Rename filter will not overwrite the target file by default if it already exists which appears to be what you are experiencing.

This snippet is out of Zend/Filter/File/Rename.php

    if (file_exists($file['target'])) {
        require_once 'Zend/Filter/Exception.php';
        throw new Zend_Filter_Exception(sprintf("File '%s' could not be renamed. It already exists.", $value));
    }

To get around this, you must pass the overwrite option like this:

$adapter->addFilter('Rename', array(
    'target'    => $talentFolderPath . DIRECTORY_SEPARATOR . $filename,
    'overwrite' => true
));

See Zend_Filter_File_Rename for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM