I am trying to rename/move a file that is living in a directory and I am giving a new name to the file and a new directory as well. Below is an snippet of such code:
$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()));
}
For some reason rename()
is returning an error like the following:
Protocol error var/www/html/editor/application/models/forms_model.php 455
Where line 455 is $success = rename($currentFilePath, $newname);
I am not sure what this mean and how to fix it so any help is more than welcome.
I am debugging this code and I am not even able to get into the catch
and see what the exact error is.
I can't find anything helpful in rename docs nor Google and a similar post I did found for move files between directories recommended exactly the same function.
One thing I must add here is that this is a VM running CentOS 6.10 and PHP 5.3.3 however files are living in the host which is Windows 10 Enterprise and shared with the VM, not sure if the problem is coming from there.
Update: A more "dark web" deeper Google search point me into this result which seems to be an issue from VirtualBox itself even if I am using it is latest version. That ticket has been closed and marked as "obsolete" not sure why but I will open a new one for VBox team so they can research into this.
Update 2:
I am trying now executing the command mv
directly into the VM as suggested by @lxg and this is the result:
$ 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
So apparently is a VBox issue with shared folders when the host is "Windows" so I will open a ticket for them on the meantime and let them know the issue still not fixed after two years.
Update 3: If anyone run into the same issue I have open a ticket for VBox team.