我正在尝试提交表单,其中一个表单值是文件上传。所有的cookie工作我只是把代码的前一部分留了出来。我收到回复说上传失败的表单数据丢失。这是表单页面http://pastebin.com/zdyzcRrn的源代码,我做错了什么/错过了什么?
<?php
//Cookie file location
$cookie_file_path = "c:/cookie.txt";
//Upload Url - the page that the form goes to. The actual form is on upload.php
$UploadUrl = "http://www.farm.co.za/takeupload.php";
//create array of data to be posted
$post_data['file'] = "@/MythBusters.S09E14.Newtons.Crane.Cradle.HDTV.XviD-FQM.torrent";
$post_data['name'] = 'MythBusters.S09E14';
$post_data['type'] = '7';
$post_data['nfo'] = '';
$post_data['descr'] = 'MythBusters.S09E14';
$post_data['submit'] = 'Do it!';
//traverse array and prepare data for posting
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$UploadPostInfo = implode ('&', $post_items);
//create cURL connection
$cr = curl_init();
curl_setopt($cr, CURLOPT_HEADER, false);
curl_setopt($cr, CURLOPT_NOBODY, false);
curl_setopt($cr, CURLOPT_URL, $UploadUrl);
curl_setopt($cr, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($cr, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($cr, CURLOPT_USERAGENT,
"Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($cr, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cr, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($cr, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($cr, CURLOPT_POST, 1);
curl_setopt($cr, CURLOPT_POSTFIELDS, $UploadPostInfo);
$html=curl_exec($cr);
print $html;
curl_close($cr);
?>
感谢您的帮助
答案 0 :(得分:0)