默認情況下,如果檔案已移動,則 CodeIgniter 4的移動函式回傳true。但是如果檔案已經存在,它會向檔案名添加一個帶有計數器的分隔符,因為我只有true我沒有新的檔案名,我想存盤在資料庫中。
我可以擴展UploadedFile課程(老實說,這對我來說很難),但我問的是我的感覺,想知道檔案名非常直觀,所以大多數都有更簡單的方法。
uj5u.com熱心網友回復:
一個小小的更正:不是move function。
它應該是move method為File實體。
根據您要獲取的名稱,有三種可用的方法:
getName()
You can retrieve the original filename provided by the client with the getName() method. This will typically be the filename sent by the client, and should not be trusted. If the file has been moved, this will return the final name of the moved file:
$name = $file->getName();
getClientName()
Always returns the original name of the uploaded file as sent by the client, even if the file has been moved:
$originalName = $file->getClientName();
getTempName()
To get the full path of the temp file that was created during the upload, you can use the getTempName() method:
$tempfile = $file->getTempName();
查看CI4 檔案了解更多資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/388803.html
上一篇:單擊按鈕時更改文本值
