Home  >  Article  >  php教程  >  PHPCURL recursive implementation of uploading files

PHPCURL recursive implementation of uploading files

WBOY
WBOYOriginal
2016-12-05 13:27:481950browse

If you are interested, you can read the previous article first, and then the two are related. Different pictures correspond to different typeIDs,
<?php<br /> <br /> /*<br /> * time: December 2, 2016 17:21:37<br /> * Function: Match the roomID in the text and the file under the folder and upload it to the server<br /> * Main parameter description: $file_qqq image file path<br /> *                                                                                                                                                                                        through $r roomID, get an array and loop through it once to get the parameter <br /> *$ Type Upload type, get <br /> according to the name of the picture *author:zhangchenyang<br /> */<br /> ini_set('max_execution_time', '0'); //Set the timeout <br /> header('content-type:text/html;charset=utf8');<br /> <br /> <br /> $act = $_GET['pass'];<br /> if ($act == 'zhangchenyang') {<br /> /**<br /> *time: December 2, 2016 16:09:33<br /> * Note: 1: Is the image path correct? * 2: Does the room id correspond? *<br /> ​​*/<br /> $file = './room400.txt'; //Uploaded roomID file<br /> $content = file_get_contents($file);<br /> //echo $content;<br /> <br /> $array = explode("rn", $content); //Convert to array<br /> //The base cabinet lists all files<br /> Function tree($directory)<br /> <br /> {<br />           global $array;<br />          $mydir = dir($directory);<br /> <br /> echo "<ul>n";<br> <br> ​​​​​while ($file = $mydir->read()) {<br> <br> If ((is_dir("$directory/$file")) AND ($file != ".") AND ($file != "..")) {<br>                     $arr = array_shift($array);<br> <br>                                                                                                                 echo "<li><font color="#ff00cc"><b>$file</b></font></li>n";<br> <br> Tree("$directory/$file");<br> <br> } Elsel <br> <br>                        global $arr;<br>                  if (is_dir('$file')) {<br> <br>                     } else {<br> <br> <br> If ($file !== '.' & $file !== ".." & $file != '') {<br>                      $img_name = mb_substr($file, 0, 1, 'utf-8');<br> If (is_numeric($img_name)) {<br> echo "<li>$file,$img_name</li>n";<br>                           $file_qqq = "$directory/$file";<br>                                                                                                                                                                                     //Parameters for constructing the interface<br>                        $r = $arr;<br>                          $t = $img_name;<br> <br> $ Return_data = UP ($ File_qqq, $ R, $ T); // 1: Path of Picture 2: Room ID 3: Transmission Type <br> If ($return_data == '200') {<br>                                                                                                                                                             $ok_info = $file_qqq . '-File name-' . $file . '-Room ID--' . $r; //File path<br> file_put_contents('ok400.txt', $ok_info, FILE_APPEND);<br> <br> } Else {s $ ERR_INFO = $ File_qqq. '-File name-'. $ File. '-The room ID--. $ R; // The path of the file <br> file_put_contents('error400.txt', $err_info, FILE_APPEND);<br> <br> <br>                                                          <br> <br>                     }<br> <br>                  }<br>             }<br> <br> <br>          }<br> <br> echo "</ul>n";<br> <br>           $mydir->close();<br> <br> }<br> <br> <br> echo "<h2>The directory is pink</h2><br>n";<br> <br> Tree("./img400");<br> Function up($file_qqq, $r, $type)<br> {<br> <br>         $u = '1';<br>          $t = '1';<br> <br> <br>          $ch = curl_init();<br>          $source = $file_qqq;<br>         $source = realpath($source);<br> //Add the @ symbol and curl will treat it as a file upload<br>         $data = array('img' => '@' . $source);<br> //$url='http://localhost/update_admin.php?u=%s&t=%s&r=%s&type=%s'; /Test interface<br>           $url = 'http://localhost/room/update_admin.php?u=%s&t=%s&r=%s&type=%s';<br>         $url = sprintf($url, $u, $t, $r, $type);<br> ​​​​​ //var_dump($url);<br>         $cfile = curl_file_create($source, 'image/jpeg', '1.jpg');<br> <br> // Set POST data<br>         $data = array('uploadedfile' => $cfile);<br>        $ch = curl_init($url);<br>         curl_setopt($ch, CURLOPT_URL, $url);<br>         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);<br>         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书<br>         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书<br>         curl_setopt($ch, CURLOPT_POST, true);<br>         curl_setopt($ch, CURLOPT_POSTFIELDS, $data);<br>         $result = curl_exec($ch);<br> //var_dump($data);<br>         $error = curl_error($ch);<br>         $b = curl_multi_getcontent($ch);<br>         curl_close($ch);<br> <br> <br>         return json_decode($result);<br> <br>     }<br> <br> <br> } else {<br> <br>     echo "<script>alert('你的口令有误请重试')</script>";<br> }

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn