【发布时间】:2014-06-23 12:12:13
【问题描述】:
我在另一台服务器上有一个带有<form> 的页面,我使用 cURL 自动设置数据。但是在这种形式中有一个文件输入<input name='file' type='file'>,现在我知道文件输入的行为与其他文件不同。
//This is my code till now.
$ch = curl_init();
//page is password protected I am not sure if this works but I hope it does.
curl_setopt($ch, CURLOPT_URL, "http://user:pass@mydomain.com/system_backup.php");
curl_setopt($ch, CURLOPT_POST, 1);
//set a file as post variable this doesn't work
curl_setopt($ch, CURLOPT_POSTFIELDS, "file=".$file."&var1=".$var1."&var2=".$var2);
$result = curl_exec($ch);
curl_close($ch);
所以我的问题是如何使用 cURL 将文件设置为 postfield。
【问题讨论】:
-
见here。