php rename錯誤原因的查找方法
打印出錯誤的原因。
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));}
解決辦法
首先,最好在以下情況之前新增一些安全檢查:
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);
知識點擴展:
語句:rename(oldname,newname,context)
參數 描述 oldname 必需,規定要重命名的文件或目錄. newname 必需,規定文件或目錄的新名稱 context 必需,規定文件句柄的環境,context 是可修改流的行為的一套選項注釋:在 php 4.3.3 之前,rename() 不能在基于 *nix 的系統中跨磁盤分區重命名文件.
注釋:用于 oldname 中的封裝協議必須和用于 newname 中的相匹配.
注釋:對 context 的支持是 php 5.0.0 添加的.
到此這篇關于php rename錯誤原因的查找方法的文章就介紹到這了,更多相關php rename錯誤原因內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
