我有一個名為“test.txt”的檔案,我需要將其上傳到 php 服務器。檔案內容改變,但檔案名不變。我想使用 curl 自動化它(它是從一個 unix 盒子上傳的)。
所以網址看起來像: curl http://myserver.com/upload.php?fname="test.txt"
我在使用 php 代碼自動接受檔案名時遇到問題。我可以使用 html 輸入/提交上傳檔案,但這需要手動干預。
這是我的代碼。我適用于手動輸入。有人可以告訴我如何將手動輸入更改為自動(來自 url)嗎?
我對php相當陌生,所以任何指導都將不勝感激。
謝謝
<?php
if(isset($_FILES['fname'])){
$errors= array();
$file_name = $_FILES['fname']['name'];
$file_tmp =$_FILES['fname']['tmp_name'];
$file_type=$_FILES['fname']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['fname']['name'])));
$extensions= array("txt");
if(empty($errors)==true){
move_uploaded_file($file_tmp,"download/".$file_name);
echo "Success";
}else{
print_r($errors);
}
}
?>
<html>
<body>
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="fname" />
<input type="submit"/>
</form>
</body>
</html>
uj5u.com熱心網友回復:
解決方案: php 檔案原樣正常。解決方案在于正確的 curl 腳本。在這種情況下:curl -F "uploadedfile=@/path/to/my/file" mywebserver.com/uploads.php這將在沒有用戶干預的情況下將檔案名發布到查詢中。感謝那些給予建議的人。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/493894.html
