我正在尝试重命名/移动一个目录中的文件,并为该文件和一个新目录指定一个新名称。下面是这类代码的一个片段:
$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
看看准确的误差是多少。
rename
docs、谷歌和类似的
post
我发现在目录之间移动文件的推荐功能与此完全相同。
更新:
一个更“黑暗的网络”更深入的谷歌搜索将我引向
this result
更新2:
mv
按照@lxg的建议,直接进入虚拟机,结果如下:
$ 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:
如果有人遇到同样的问题,我会打开一个
ticket
对于VBox团队。