PHP copy函式使用案例程式碼解析
阿新 • • 發佈:2020-09-02
copy—拷貝檔案
說明
copy(string$source,string$dest[,resource$context] ) :bool
將檔案從source拷貝到dest。
如果要移動檔案的話,請使用rename()函式。
引數
source
原始檔路徑。
dest
目標路徑。如果dest是一個 URL,則如果封裝協議不支援覆蓋已有的檔案時拷貝操作會失敗。
Warning
如果目標檔案已存在,將會被覆蓋。
context
A valid context resource created withstream_context_create().
返回值
成功時返回TRUE, 或者在失敗時返回FALSE。
更新日誌
版本 | 說明 |
---|---|
5.3.0 | 增加了對 context 的支援。 |
4.3.0 | 如果啟用了“fopen wrappers”的話,source和dest都可以是 URL。更多細節見fopen()。 |
案例
Example #1copy()例子
<?php $file = 'example.txt'; $newfile = 'example.txt.bak'; if (!copy($file,$newfile)) { echo "failed to copy $file...\n"; } ?>
參考
- move_uploaded_file()- 將上傳的檔案移動到新位置
- rename()- 重新命名一個檔案或目錄
- The section of the manual abouthandling file uploads
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。