我正在编写一个程序,需要通过http将“log.txt”上传到web服务器。
我已经搜索了一下,找到了以下内容:
Delphi XE:
我已经搜索了一下,找到了以下内容:
Delphi XE:
procedure TForm1.Button1Click(Sender: TObject);
begin
idhttp1.Post('http://127.0.0.1/GET2.php', 'C:\Users\Someone\Desktop\log.txt')
end;
PHP :-
<?php
$uploaddir = "uploads/";
$uploadfile = $uploaddir . basename( $_FILES['file']['name']);
if(move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile))
{
echo "The file has been uploaded successfully";
}
else
{
echo "There was an error uploading the file";
}
?>
但没有文件被上传
谢谢你的帮助
$_FILES
进行POST
时,源文件名在$_FILES['fieldName']['name']
中,详见我在回答中提供的文档。当使用fopen("php://input")
进行PUT
时,源文件名在$_SERVER['REQUEST_URI']
中,你需要解析出文件名,参考Get only filename from url in php without any variable values which exist in the url。 - Remy Lebeau