如何使用 PHP 中的 Curl 将文件上传到另一个网站并获取响应页面?
网站:http://www.postto.me http://www.postto.me
<form action="posttome.php" enctype="multipart/form-data" method="post">
<input type="hidden" value="2097152" name="MAX_FILE_SIZE">
<input type="file" size="30" class="input" name="img">
<input type="submit" class="input" value="Upload" name="upload">
</form>
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
curl_setopt($ch, CURLOPT_URL, "http://www.postto.me/upload.php");
curl_setopt($ch, CURLOPT_POST, true);
// same as <input type="file" name="file_box">
$post = array(
"img"=>$_FILES["img"]["tmp_name"],
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$response = curl_exec($ch);
echo $response;
echo $_FILES["img"]["tmp_name"];
}
?>
它不起作用[如何]?
除了保罗·施赖伯的回答之外:
根据如何使用curl和php上传文件 https://stackoverflow.com/questions/15200632/how-to-upload-file-using-curl-with-php,从 php 5.5 开始你需要使用curl_file_create($path)
代替"@$path"
.
经测试:确实有效。
随着@
方式没有文件被上传。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)