共計(jì) 619 個(gè)字符,預(yù)計(jì)需要花費(fèi) 2 分鐘才能閱讀完成。
要上傳文件到指定目錄,可以使用 PHP 的內(nèi)置函數(shù) move_uploaded_file()。
move_uploaded_file() 函數(shù)將上傳的文件移動(dòng)到指定目錄中。它的語法如下:
move_uploaded_file (string $filename , string $destination) : bool
其中,$filename 是上傳文件的臨時(shí)存儲(chǔ)路徑,$destination 是目標(biāo)存儲(chǔ)路徑。
以下是一個(gè)示例,演示了如何將上傳的文件保存到指定目錄中:
<?php
$targetDirectory = "/path/to/destination/directory/";
$targetFile = $targetDirectory . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $targetFile)) {echo " 文件上傳成功。";} else {echo " 文件上傳失敗。";}
在上面的示例中,$_FILES[“fileToUpload”][“tmp_name”] 是上傳文件的臨時(shí)存儲(chǔ)路徑,$_FILES”fileToUpload” 是上傳文件的原始文件名。$targetFile 變量用于指定目標(biāo)存儲(chǔ)路徑。
請(qǐng)確保指定的目標(biāo)目錄具有適當(dāng)?shù)臋?quán)限,以便 PHP 腳本可以在其中創(chuàng)建文件。
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!
正文完