PHP函式:CURLFile::getPostFilename()
適用版本:PHP 5.5.0+
用法: CURLFile::getPostFilename() 函式用於獲取上傳檔案在 POST 請求中的檔名。
示例:
// 定義上傳檔案路徑
$file_path = '/path/to/file.jpg';
// 建立 CURLFile 物件
$cfile = new CURLFile($file_path);
// 獲取檔案在 POST 請求中的檔名
$post_filename = $cfile->getPostFilename();
// 輸出檔名
echo "POST 檔名:" . $post_filename;
在上面的示例中,我們首先定義了要上傳的檔案路徑。然後,我們透過例項化 CURLFile 類建立了一個 CURLFile 物件。接下來,我們使用 getPostFilename()
方法從 CURLFile 物件中獲取檔案在 POST 請求中的檔名。最後,我們輸出了檔名。
請注意,CURLFile::getPostFilename()
函式僅適用於使用 CURL 傳送 POST 請求時上傳檔案。如果未經過 POST 請求上傳檔案,或者使用其他方法傳送請求,則該函式將沒有效果。
此外,需要確保在伺服器上安裝了 cURL 擴充套件,才能使用 CURLFile::getPostFilename()
函式。