• <i id='ln3Rt'><tr id='ln3Rt'><dt id='ln3Rt'><q id='ln3Rt'><span id='ln3Rt'><b id='ln3Rt'><form id='ln3Rt'><ins id='ln3Rt'></ins><ul id='ln3Rt'></ul><sub id='ln3Rt'></sub></form><legend id='ln3Rt'></legend><bdo id='ln3Rt'><pre id='ln3Rt'><center id='ln3Rt'></center></pre></bdo></b><th id='ln3Rt'></th></span></q></dt></tr></i><div id='ln3Rt'><tfoot id='ln3Rt'></tfoot><dl id='ln3Rt'><fieldset id='ln3Rt'></fieldset></dl></div>
    <tfoot id='ln3Rt'></tfoot>
    1. <legend id='ln3Rt'><style id='ln3Rt'><dir id='ln3Rt'><q id='ln3Rt'></q></dir></style></legend>

        • <bdo id='ln3Rt'></bdo><ul id='ln3Rt'></ul>

        <small id='ln3Rt'></small><noframes id='ln3Rt'>

        php使用curl模拟post传输文件的实例代码

        时间:2024-11-01

        <i id='1DHU5'><tr id='1DHU5'><dt id='1DHU5'><q id='1DHU5'><span id='1DHU5'><b id='1DHU5'><form id='1DHU5'><ins id='1DHU5'></ins><ul id='1DHU5'></ul><sub id='1DHU5'></sub></form><legend id='1DHU5'></legend><bdo id='1DHU5'><pre id='1DHU5'><center id='1DHU5'></center></pre></bdo></b><th id='1DHU5'></th></span></q></dt></tr></i><div id='1DHU5'><tfoot id='1DHU5'></tfoot><dl id='1DHU5'><fieldset id='1DHU5'></fieldset></dl></div>
        • <legend id='1DHU5'><style id='1DHU5'><dir id='1DHU5'><q id='1DHU5'></q></dir></style></legend>

              <small id='1DHU5'></small><noframes id='1DHU5'>

                <tbody id='1DHU5'></tbody>

                <tfoot id='1DHU5'></tfoot>
                • <bdo id='1DHU5'></bdo><ul id='1DHU5'></ul>

                  文件发送的代码如下:
                  <?
                  $url = 'http://127.0.0.1/fujian/jieshou.php'; // 目标URL
                  $filePath2 = iconv("utf-8","gb2312",'D:/MYOA/webroot/fujian/1/副本.txt'); // 文件路
                  $filePath1 = iconv("utf-8","gb2312",'D:/MYOA/webroot/fujian/1/1.txt'); // 文件路径径
                   
                  $cfile1 = curl_file_create($filePath1);
                  $cfile2 = curl_file_create($filePath2);
                  $data = array('file1' => $cfile1,'file2' => $cfile2,'aa'=>'bbbb');
                   
                  $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_RETURNTRANSFER, true);
                  $response = curl_exec($ch);
                   
                  if(curl_errno($ch)){
                      echo 'Error:' . curl_error($ch);
                  }
                  else{
                      echo 'Response:' . $response;
                  }
                   
                  curl_close($ch);
                   
                  ?>
                  
                  接口文件代码如下,名称为jiekou.php
                  <?
                   
                  //$postData = file_get_contents('php://input');
                  $aa=$_REQUEST["aa"];
                  $jintiantxt=date("Y-m-d").".txt";
                  $myfile = fopen($jintiantxt, "a") or die("Unable to open file!");//w
                  $txt =date("Y-m-d H:i:s")."\r\n".$aa."\r\n";
                  fwrite($myfile, $txt);
                   
                  fclose($myfile);
                   
                  /*
                  if (isset($_FILES['file']) && $_FILES['file']['error'] == UPLOAD_ERR_OK) {
                      $tmpName = $_FILES['file']['tmp_name'];
                      $name = basename($_FILES['file']['name']);
                      $destination = "./2/{$name}";
                   
                      if (move_uploaded_file($tmpName, $destination)) {
                          echo "File uploaded successfully to: {$destination}";
                      } else {
                          echo "Failed to move uploaded file.";
                      }
                  } else {
                      echo "No file uploaded or error occurred.";
                  }
                  */
                  $save_dir="D:/MYOA/webroot/fujian/2/";
                  foreach ($_FILES as $key => $file) {
                      if ($file["error"] > 0) {
                          echo "错误: " . $file["error"] . "<br />";
                      } else {
                          echo "文件名: " . $file["name"] . "<br />";
                          echo "类型: " . $file["type"] . "<br />";
                          echo "大小: " . ($file["size"] / 1024) . " Kb<br />";
                          echo "临时文件位置: " . $file["tmp_name"];
                     	    // windows下路径有问题时进行处理(这个似乎是错的)
                  	    // $_FILES[$key]["tmp_name"] = str_replace("\\", "//", $file["tmp_name"]);
                          // 保存文件
                          if (file_exists($save_dir . $file["name"])) {
                              echo $file["name"] . " 已存在. ";
                          } else {
                              move_uploaded_file($file["tmp_name"], $save_dir . $file["name"]);
                              echo "存储到: " . $save_dir . $file["name"];
                          }
                      }
                  }
                   
                  ?>
                   
                  上一篇:PHP图形验证码实例代码 下一篇:没有了

                  相关文章

                  <i id='QWkHC'><tr id='QWkHC'><dt id='QWkHC'><q id='QWkHC'><span id='QWkHC'><b id='QWkHC'><form id='QWkHC'><ins id='QWkHC'></ins><ul id='QWkHC'></ul><sub id='QWkHC'></sub></form><legend id='QWkHC'></legend><bdo id='QWkHC'><pre id='QWkHC'><center id='QWkHC'></center></pre></bdo></b><th id='QWkHC'></th></span></q></dt></tr></i><div id='QWkHC'><tfoot id='QWkHC'></tfoot><dl id='QWkHC'><fieldset id='QWkHC'></fieldset></dl></div>
                  <legend id='QWkHC'><style id='QWkHC'><dir id='QWkHC'><q id='QWkHC'></q></dir></style></legend>

                    1. <tfoot id='QWkHC'></tfoot>
                        <bdo id='QWkHC'></bdo><ul id='QWkHC'></ul>

                    2. <small id='QWkHC'></small><noframes id='QWkHC'>