Home> php教程> php手册> body text

PHPCURL recursive implementation of uploading files

WBOY
Release: 2016-12-05 13:27:48
Original
1887 people have browsed it

If you are interested, you can read the previous article first, and then the two are related. Different pictures correspond to different typeIDs,

/*
* time: December 2, 2016 17:21:37
* Function: Match the roomID in the text and the file under the folder and upload it to the server
* Main parameter description: $file_qqq image file path
* through $r roomID, get an array and loop through it once to get the parameter
*$ Type Upload type, get
according to the name of the picture *author:zhangchenyang
*/
ini_set('max_execution_time', '0'); //Set the timeout
header('content-type:text/html;charset=utf8');


$act = $_GET['pass'];
if ($act == 'zhangchenyang') {
/**
*time: December 2, 2016 16:09:33
* Note: 1: Is the image path correct? * 2: Does the room id correspond? *
*/
$file = './room400.txt'; //Uploaded roomID file
$content = file_get_contents($file);
//echo $content;

$array = explode("rn", $content); //Convert to array
//The base cabinet lists all files
Function tree($directory)

{
global $array;
$mydir = dir($directory);

echo "

    n";

    while ($file = $mydir->read()) {

    If ((is_dir("$directory/$file")) AND ($file != ".") AND ($file != "..")) {
    $arr = array_shift($array);

    echo "
  • $file
  • n";

    Tree("$directory/$file");

    } Elsel

    global $arr;
    if (is_dir('$file')) {

    } else {


    If ($file !== '.' & $file !== ".." & $file != '') {
    $img_name = mb_substr($file, 0, 1, 'utf-8');
    If (is_numeric($img_name)) {
    echo "
  • $file,$img_name
  • n";
    $file_qqq = "$directory/$file";
    //Parameters for constructing the interface
    $r = $arr;
    $t = $img_name;

    $ Return_data = UP ($ File_qqq, $ R, $ T); // 1: Path of Picture 2: Room ID 3: Transmission Type
    If ($return_data == '200') {
    $ok_info = $file_qqq . '-File name-' . $file . '-Room ID--' . $r; //File path
    file_put_contents('ok400.txt', $ok_info, FILE_APPEND);

    } Else {s $ ERR_INFO = $ File_qqq. '-File name-'. $ File. '-The room ID--. $ R; // The path of the file
    file_put_contents('error400.txt', $err_info, FILE_APPEND);




    }

    }
    }


    }

    echo "
n";

$mydir->close();

}


echo "

The directory is pink


n";

Tree("./img400");
Function up($file_qqq, $r, $type)
{

$u = '1';
$t = '1';


$ch = curl_init();
$source = $file_qqq;
$source = realpath($source);
//Add the @ symbol and curl will treat it as a file upload
$data = array('img' => '@' . $source);
//$url='http://localhost/update_admin.php?u=%s&t=%s&r=%s&type=%s'; /Test interface
$url = 'http://localhost/room/update_admin.php?u=%s&t=%s&r=%s&type=%s';
$url = sprintf($url, $u, $t, $r, $type);
//var_dump($url);
$cfile = curl_file_create($source, 'image/jpeg', '1.jpg');

// Set POST data
$data = array('uploadedfile' => $cfile);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //不验证证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //不验证证书
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($ch);
//var_dump($data);
$error = curl_error($ch);
$b = curl_multi_getcontent($ch);
curl_close($ch);


return json_decode($result);

}


} else {

echo "";
}

source:php.cn
Statement of this Website
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
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!