我想打印出错误的原因.
error_get_last()似乎没有返回任何内容.rename()返回TRUE | FALSE而不是异常.
if (!rename($file->filepath, $full_path)) {
$error = error_get_last();
watchdog('name', "Failed to move the uploaded file from %source to %dest", array('%source' => $file->filepath, '%dest' => $full_path));
}
Run Code Online (Sandbox Code Playgroud)
首先,在以下情况之前添加一些安全检查是更好的做法:
if (file_exists($old_name) &&
((!file_exists($new_name)) || is_writable($new_name))) {
rename($old_name, $new_name);
}
Run Code Online (Sandbox Code Playgroud)
其次,您可以打开错误报告:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
Run Code Online (Sandbox Code Playgroud)
答案是“另一个错误处理程序”正在根据http://php.net/manual/en/function.error-get-last.php的 php 手册中的注释捕获错误。在本例中,它是 drupal 错误处理程序,错误被捕获到那里的错误日志中。