is_uploaded_file() 函數檢查檔案是否是透過 HTTP POST 上傳的。如果檔案是透過 HTTP POST 上傳的,則該函數傳回 TRUE。失敗時回傳 FALSE。
is_uploaded_file(file_path)
file_path -指定要檢查的檔案。
如果檔案是透過 HTTP POST 上傳的,is_uploaded_file() 函數將會傳回 TRUE。失敗時回傳 FALSE。
假設我們正在上傳包含以下內容的檔案「new.txt」。
This is demo text!
<?php // checking for file is uploaded via HTTP POST if (is_uploaded_file($_FILES['userfile'][‘new.txt'])) { echo "File ". $_FILES['userfile'][‘new.txt'] ." uploaded successfully!</p><p>"; // displaying contents of the uploaded file echo "Reading Contents of the file:</p><p>"; readfile($_FILES['userfile'][‘new.txt']); } else { echo "File ". $_FILES['userfile'][‘new.txt'] ." failed in uploading! File upload attack could be the reason!</p><p>"; } ?>
File new.txt uploaded successfully! Reading Contents of the file: This is demo text!
Let us see another example with file “details.txt”.
# Live
# Live Demo<?php $file = "newdetailstxt"; if(is_uploaded_file($file)) { echo ("Uploaded via HTTP POST"); } else { echo ("Not uploaded via HTTP POST"); } ?>
Not uploaded via HTTP POST!###
以上是is_uploaded_file()函數是PHP中的一個函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!