我正在將包含以下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