无法重命名文件'C:\ xampp \ tmp \ php3226.tmp'。(File 'C:\xampp\tmp\php3226.tmp' co

编程入门 行业动态 更新时间:2024-10-27 18:32:12
无法重命名文件'C:\ xampp \ tmp \ php3226.tmp'。(File 'C:\xampp\tmp\php3226.tmp' could not be renamed. It already exists error in zend, how to?)

我正在使用此功能将文件上传到磁盘:

$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.

更多推荐

本文发布于:2023-07-30 22:03:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340287.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重命名   文件   tmp   xampp   zend

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!