我有问题,我想将文件远程上传到filefactory,... 我成功登录并转到上传页面,但是当我在postfields时出现错误:“没有发送文件数据”。任何人都可以帮忙吗??
我的代码:
//user data
$email="somebody@yahoo.com";
$pass="somepass";
$cookie="cookie.txt";
//url data
$host="http://www.filefactory.com";
$logURL="http://www.filefactory.com/member/login.php";
//postdata
$logPOST="email=".urlencode($email)."&password=".urlencode($pass);
//login
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $logURL);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $logPOST);
curl_exec($ch);
curl_close($ch);
//go to uploads section
$uploadRefferer="http://www.filefactory.com/u/local/?login=1";
$uploadURL="http://upload.filefactory.com/upload.php";
$filename="@test.png";
//try to upload file
$ch=curl_init();
curl_setopt($ch, CURLOPT_URL, $uploadURL);
curl_setopt($ch, CURLOPT_REFERER, $uploadRefferer);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,ALL FIELDS THAT I NEED);
curl_exec($ch);
文件test.php在带有cookie和index.php的samo文件夹中(这就是运行它)...尝试使用localhost,服务器,但是不行。
答案 0 :(得分:0)
这将完成工作:
curl_setopt($ch, CURLOPT_POSTFIELDS, Array(
'redirect' => 1,
'saveTo' => 0,
'file' => $filename
));