Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
转换为PHP REST CURL POST_Php_Rest_Post_Upload_Onedrive - Fatal编程技术网

转换为PHP REST CURL POST

转换为PHP REST CURL POST,php,rest,post,upload,onedrive,Php,Rest,Post,Upload,Onedrive,如何将此代码转换为PHP REST CURL POST POST https://apis.live.net/v5.0/me/skydrive/files?access_token=ACCESS_TOKEN Content-Type: multipart/form-data; boundary=A300x --A300x Content-Disposition: form-data; name="file"; filename="HelloWorld.txt" Content-Type: a

如何将此代码转换为PHP REST CURL POST

POST https://apis.live.net/v5.0/me/skydrive/files?access_token=ACCESS_TOKEN

Content-Type: multipart/form-data; boundary=A300x

--A300x
Content-Disposition: form-data; name="file"; filename="HelloWorld.txt"
Content-Type: application/octet-stream

Hello, World!
--A300x--
编辑:未阅读全部帖子,已修复。

希望对您有所帮助:

 <?php
    $headers = array('token: pacexpressx1x2x3j' );
    $data = array(
    "STATUS" => "insert" ,
    "NAME"   =>  utf8_encode("Test integration 10"),
    "COD_AREA"   =>  "4",
    "DESC_AREA_"  =>   utf8_encode("info/IT"),
    "JOB" =>  utf8_encode("TEST job"),
    "COMPANY" => "4",
    "DESC_COMPANY" => utf8_encode("XPTO1"),
    "file" => '@/home/user/test.png');

    $url = 'your_link';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $output = curl_exec($ch);
    echo($output) . PHP_EOL;
    curl_close($ch);

您最好阅读CURL:。通常情况下,如果答案中包含对代码意图的解释,以及在不介绍其他内容的情况下解决问题的原因,那么答案会更有帮助。
 <?php
    $headers = array('token: pacexpressx1x2x3j' );
    $data = array(
    "STATUS" => "insert" ,
    "NAME"   =>  utf8_encode("Test integration 10"),
    "COD_AREA"   =>  "4",
    "DESC_AREA_"  =>   utf8_encode("info/IT"),
    "JOB" =>  utf8_encode("TEST job"),
    "COMPANY" => "4",
    "DESC_COMPANY" => utf8_encode("XPTO1"),
    "file" => '@/home/user/test.png');

    $url = 'your_link';
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

    $output = curl_exec($ch);
    echo($output) . PHP_EOL;
    curl_close($ch);
    echo 'Here is some more debugging info:';
    echo "\n<hr />\n";
    print_r($_FILES);
    echo "\n<hr />\n";
    print_r($_POST);
    print "</pr" . "e>\n"; 
    echo "\n<hr />\n";
    // here you will record the file in your server... you can choose a directory if you want
    file_put_contents($_FILES['file']['name'],file_get_contents($_FILES['file']['tmp_name']));