<code> <?php function upload_file($url,$filename,$path){ $data = array('pic'=>'@'.realpath($path).";filename=".$filename); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $return_data = curl_exec($ch); curl_close($ch); $decode = json_decode($return_data); echo $decode->original_pic; } if ($_POST) { $url = 'https://127.0.0.1/img.php'; $tmpname = $_FILES['fname']['name']; $tmpfile = $_FILES['fname']['tmp_name']; upload_file($url,$tmpname,$tmpfile); exit; } echo '<form action="" enctype="multipart/form-data" method="post"> <input type="text" name="fname" /> <input type="file" name="fname" /> <input type="submit" value="Submit" /> </form>'; ?> </code>
程式碼如上,為什麼刪除就無法執行post?
<code> <?php function upload_file($url,$filename,$path){ $data = array('pic'=>'@'.realpath($path).";filename=".$filename); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true ); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $return_data = curl_exec($ch); curl_close($ch); $decode = json_decode($return_data); echo $decode->original_pic; } if ($_POST) { $url = 'https://127.0.0.1/img.php'; $tmpname = $_FILES['fname']['name']; $tmpfile = $_FILES['fname']['tmp_name']; upload_file($url,$tmpname,$tmpfile); exit; } echo '<form action="" enctype="multipart/form-data" method="post"> <input type="text" name="fname" /> <input type="file" name="fname" /> <input type="submit" value="Submit" /> </form>'; ?> </code>
程式碼如上,為什麼刪除就無法執行post?
有沒有什麼錯誤訊息啊!貼出來看看
。 。 。應該有報錯的啊,執行是空返回嗎?那隻能打斷點看看那一步出問題
上傳的文件資訊應該是會存在放$_FILES 而不會存在放$_POST裡面然後你的post裡面不就沒東西了提前打出$_POST
沒有找到文檔說明只是試驗了下可以把submit設置一個name