php - PHP 5.3.3 重命名函数因“协议错误”而失败
问题描述
我正在尝试重命名/移动位于目录中的文件,并且我正在为文件和新目录指定一个新名称。以下是此类代码的片段:
$currentFilePath = FCPATH . $forms->form_filepath;
$current_name = $stageDir . '/' . $forms->FormName . '.pdf';
$newname = file_exists($current_name) ? uniqid('', true) . 'pdf' : $current_name;
// $currentFilePath = "/var/www/html/epa_editor/public/epa_forms/archive/Clone_16621_SamplePDFFile_5mb.pdf"
// $newname = "/var/www/html/epa_editor/public/epa_forms/stage/testing (Clone of Form #: 15615).pdf"
try {
$success = rename($currentFilePath, $newname);
} catch (Exception $e) {
$error = $e->getMessage();
log_message('error', print_r('An error has occurred: %s', $e->getMessage()));
}
由于某种原因rename()
返回如下错误:
协议错误 var/www/html/editor/application/models/forms_model.php 455
第 455 行在哪里,$success = rename($currentFilePath, $newname);
我不确定这意味着什么以及如何解决它,所以任何帮助都非常受欢迎。
我正在调试这段代码,我什至无法进入catch
并查看确切的错误是什么。
我在重命名文档和谷歌中找不到任何有用的东西,而我发现的在目录之间移动文件的类似帖子推荐了完全相同的功能。
我必须在这里添加的一件事是,这是一个运行 CentOS 6.10 和 PHP 5.3.3 的 VM,但是文件存在于 Windows 10 Enterprise 的主机中并与 VM 共享,不确定问题是否来自那里。
更新: 一个更“暗网”更深的谷歌搜索将我指向这个结果,这似乎是 VirtualBox 本身的一个问题,即使我使用的是最新版本。该票已关闭并标记为“过时”,不知道为什么,但我将为 VBox 团队打开一张新票,以便他们对此进行研究。
更新 2:
我现在正在尝试mv
按照@lxg 的建议将命令直接执行到 VM 中,结果如下:
$ mv /var/www/html/epa_editor/public/epa_forms/archive/Clone_16621_SamplePDFFile_5mb.pdf "/var/www/html/epa _editor/public/epa_forms/stage/testing (Clone of Form #: 15615).pdf"
mv: cannot move `/var/www/html/epa_editor/public/epa_forms/archive/Clone_16621_SamplePDFFile_5mb.pdf' to `/var/www/html/epa_editor/public/epa_forms/stage/testing (Clone of Form #: 15615).pdf': Protocol error
因此,当主机是“Windows”时,显然是共享文件夹的 VBox 问题,所以我会同时为他们开一张票,让他们知道两年后问题仍未解决。
更新 3: 如果有人遇到同样的问题,我会为 VBox 团队开一张票。