php rename錯誤原因的查找方法:1、新增一些安全檢查;2、開啟錯誤報告“error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);”。
本文操作環(huán)境:windows7系統(tǒng)、PHP7.1版,DELL G3電腦
PHP:rename()如何找到錯誤原因?
我想打印出錯誤的原因。
error_get_last()似乎沒有返回任何內(nèi)容。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)); }
解決辦法
首先,最好在以下情況之前新增一些安全檢查:
if (file_exists($old_name) && ((!file_exists($new_name)) || is_writable($new_name))) { rename($old_name, $new_name); }
其次,可以開啟錯誤報告:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
推薦學習:《PHP視頻教程》