<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>
The code is as above, why can’t I post after deleting ?
<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>
The code is as above, why can’t I post after deleting ?
Is there any error message? Post it and take a look
. . . There should be an error. Does the execution return nothing? Then we can only interrupt and see which step causes the problem
The uploaded file information should be stored in $_FILES and not in $_POST. Then there will be nothing in your post. Type $_POST in advance.
I didn’t find the document description. I just tried it and set one for submit. name