我想登录一个站点,然后使用 curl 上传一个文件
我已成功登录网站,现在我想使用相同的 curl 连接上传文件。可能吗?
到目前为止我的代码:
$id ='myusername';
$password ='mypassword';
$cookie_file_path = "cookie.txt";
$agent =$_SERVER['HTTP_USER_AGENT'];
$getfile='http://archive.org/download/TestVideo_935/Backntro.mp4';
$getfile=file_get_contents($getfile);
$POSTFIELDS = array(
'username'=>$id,
'password'=>$password,
'uploadfile'=>'@'.$getfile
);
//post info for login
$LOGINURL = "http://****.com/**/;
$reffer = "http://*****.com/***/";//path to upload file
//in my case I want to upload video as this site is video site
$ch = curl_init ($LOGINURL);
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS);
curl_setopt($session, CURLOPT_HTTPHEADER, array(
"Content-Type:multipart/form-data",
));
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt ($ch, CURLOPT_COOKIEFILE,$cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, $reffer);
curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$info = curl_getinfo($ch);
$result = curl_exec ($ch);
print_r($info);
print_r($result);
任何帮助将不胜感激 !!非常感谢 !
<form method="post" action="userfiles" enctype="multipart/form-data">
<div class="formrow">
<label for="uploadfile">File</label>
<input type="file" name="uploadfile" id="uploadfile" />
<span id="note_uploadfile"></span></div>
<div class="formrow"><label for="uploadname">
Name</label><input type="text" name="uploadname" id="uploadname" /> <span
<div class="submitrow"><label></label>
</form>