サイトにログインしてから、curl を使用してファイルをアップロードしたい
Web サイトへのログインに成功しました。同じ 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>