我正在使用此功能将文件上传到磁盘:
$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; }我收到这条消息:
消息:无法重命名文件'C:\ xampp \ tmp \ php3226.tmp'。 它已经存在。
有什么想法发生了什么?
谢谢。
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.
最满意答案
默认情况下, 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)); }要解决这个问题,您必须传递overwrite选项,如下所示:
$adapter->addFilter('Rename', array( 'target' => $talentFolderPath . DIRECTORY_SEPARATOR . $filename, 'overwrite' => true ));有关更多详细信息,请参阅Zend_Filter_File_Rename 。
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.
更多推荐
发布评论