我正在将包含以下html代码的文件提交给php文件。我想要做的是在php中获取该文件,然后将该文件设置为cURL的参数值作为postfields,然后执行url,我该怎么做?通过php上传文件时遇到问题
下面是HTML:
<form name="frm" id="frm" method="post" action="fileSubmit.php" enctype="multipart/form-data">
<input type="file" name="file" id="file"/>
<input type="submit" name="submit" value="submit" />
</form>
这里是PHP提前
<?php
if(isset($_REQUEST['submit'])) {
$curl = curl_init("myDomain/submitFile";);
$file = "file=".file_get_contents($_FILES["file"]["name"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_TIMEOUT, 60);
curl_setopt($curl, CURLOPT_POST, 0);
curl_setopt($curl, CURLOPT_POSTFIELDS, $file);
$resp = curl_exec($curl);
curl_close($curl);
}
?>
谢谢!
什么问题?显示php代码 –
请更清楚您的问题显示代码和问题在哪里? –
这是我试图上传文件的php代码。我做错了什么? (isset($ _ REQUEST ['submit'])) <?php if(isset($ _ REQUEST ['submit'])) {0} $ file =“file =”。file_get_contents($ _ FILES [“file”] [“name”]); curl_setopt($ curl,CURLOPT_RETURNTRANSFER,1); curl_setopt($ curl,CURLOPT_HEADER,0); curl_setopt($ curl,CURLOPT_TIMEOUT,60); curl_setopt($ curl,CURLOPT_POST,0); curl_setopt($ curl,CURLOPT_POSTFIELDS,$ file); $ resp = curl_exec($ curl); curl_close($ curl); } ?> – seeker