我在本地服務器上有一個簡單的 php 網站,它只是在服務器上上傳任何型別的檔案(我本地電腦上的一個目錄)。

我想要的是,當我上傳一個php檔案時,我希望它執行,而不僅僅是保存它。沒有安全性,我只是想看看上傳時是否可以執行php腳本。我怎樣才能做到這一點?
uj5u.com熱心網友回復:
您可以將檔案寫入磁盤,然后再要求它。如果您不需要永久檔案,那么我建議您使用臨時檔案。
我建議然后使用require_once來執行檔案。
類似于(為簡單起見,我使用硬編碼的檔案名):
<?php
// Logic for handling the file upload goes here
// Demo script to run, this should be the contents of the file uploaded.
$upload_contents = '<?php echo "I have been uploaded."; ?>';
// Write the file to disk, I've used a hard-coded name and contents to serve the purpose of an example
file_put_contents('UploadedScript.php', $upload_contents);
// Since security is not a requirement, we will just straight require the file so PHP will execute it.
require_once('UploadedScript.php');
?>
編輯:如果您想上傳任何型別的檔案,但只執行帶有“.php”擴展名的檔案,那么我建議您查看這些答案。然后您可以在執行之前檢查以確保上傳的檔案是“.php”擴展名。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/374949.html
