我有一个基于css、HTML和PHP的简单CMS。我制作了一个cURL脚本来通过POST更新内容,包括模板(文本和HTML的混合)。
curl_setopt ($upload, CURLOPT_POSTFIELDS, $postfields);
和&postfields:
$postfields["person"] = "Kris";
$postfields["action"] = "Update";
$postfields["page"] = "Name of the page";
$postfields["newcontent"] = $post;
+
$post=file_get_contents("update.txt");
我需要的是通过POST发送文本文件(update.txt)中指定的数据,包括html/css.php的混合有什么想法吗?:)谢谢
使用问题字段名更新并设置文件的Mimetype
根据使用cURL和PHP通过POST发送文件以及PHP手册,您可以执行以下操作:
$file_name_with_full_path = realpath('update.txt');
$postfields = array('person' => 'Kris',
'action' => 'Update',
'page' => 'Name of the page',
'newcontent'=>'@'.$file_name_with_full_path.';type=html');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$target_url);
curl_setopt($ch, CURLOPT_POST,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec ($ch);
curl_close ($ch);
echo $result;
排序:)
$postfields["newcontent"] = $post;
+
$newcontent = 'post.txt';
$post = file_get_contents($newcontent);