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);}
其次,可以開啟錯誤報(bào)告:
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
知識點(diǎn)擴(kuò)展:
語句:rename(oldname,newname,context)
參數(shù) 描述 oldname 必需,規(guī)定要重命名的文件或目錄. newname 必需,規(guī)定文件或目錄的新名稱 context 必需,規(guī)定文件句柄的環(huán)境,context 是可修改流的行為的一套選項(xiàng)注釋:在 php 4.3.3 之前,rename() 不能在基于 *nix 的系統(tǒng)中跨磁盤分區(qū)重命名文件.
注釋:用于 oldname 中的封裝協(xié)議必須和用于 newname 中的相匹配.
注釋:對 context 的支持是 php 5.0.0 添加的.
到此這篇關(guān)于php rename錯誤原因的查找方法的文章就介紹到這了,更多相關(guān)php rename錯誤原因內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. ASP刪除img標(biāo)簽的style屬性只保留src的正則函數(shù)2. Spring注入Date類型的三種方法總結(jié)3. PHP循環(huán)與分支知識點(diǎn)梳理4. HTML 絕對路徑與相對路徑概念詳細(xì)5. ASP實(shí)現(xiàn)加法驗(yàn)證碼6. ASP基礎(chǔ)入門第二篇(ASP基礎(chǔ)知識)7. PHP設(shè)計(jì)模式中工廠模式深入詳解8. ASP基礎(chǔ)知識Command對象講解9. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享10. PHP session反序列化漏洞超詳細(xì)講解
