Pat*_*cow 0 php zend-framework image-upload
我正在使用此功能将文件上传到磁盘:
$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;
}
Run Code Online (Sandbox Code Playgroud)
我收到这条消息:
消息:无法重命名文件'C:\ xampp\tmp\php3226.tmp'.它已经存在.
有什么想法发生了什么?
谢谢.
Rename默认情况下,过滤器不会覆盖目标文件,如果它已经存在,看起来就像您正在经历的那样.
这个片段是不合适的 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));
}
Run Code Online (Sandbox Code Playgroud)
要解决这个问题,您必须通过以下overwrite选项:
$adapter->addFilter('Rename', array(
'target' => $talentFolderPath . DIRECTORY_SEPARATOR . $filename,
'overwrite' => true
));
Run Code Online (Sandbox Code Playgroud)
有关更多详细信息,请参阅Zend_Filter_File_Rename.