久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    <legend id='1SNEB'><style id='1SNEB'><dir id='1SNEB'><q id='1SNEB'></q></dir></style></legend>

        <bdo id='1SNEB'></bdo><ul id='1SNEB'></ul>

    1. <i id='1SNEB'><tr id='1SNEB'><dt id='1SNEB'><q id='1SNEB'><span id='1SNEB'><b id='1SNEB'><form id='1SNEB'><ins id='1SNEB'></ins><ul id='1SNEB'></ul><sub id='1SNEB'></sub></form><legend id='1SNEB'></legend><bdo id='1SNEB'><pre id='1SNEB'><center id='1SNEB'></center></pre></bdo></b><th id='1SNEB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='1SNEB'><tfoot id='1SNEB'></tfoot><dl id='1SNEB'><fieldset id='1SNEB'></fieldset></dl></div>
    2. <tfoot id='1SNEB'></tfoot>
      1. <small id='1SNEB'></small><noframes id='1SNEB'>

        使用 file_get_contents 上傳文件

        Upload a file using file_get_contents(使用 file_get_contents 上傳文件)
        • <bdo id='FPkKR'></bdo><ul id='FPkKR'></ul>
            <tbody id='FPkKR'></tbody>

          1. <i id='FPkKR'><tr id='FPkKR'><dt id='FPkKR'><q id='FPkKR'><span id='FPkKR'><b id='FPkKR'><form id='FPkKR'><ins id='FPkKR'></ins><ul id='FPkKR'></ul><sub id='FPkKR'></sub></form><legend id='FPkKR'></legend><bdo id='FPkKR'><pre id='FPkKR'><center id='FPkKR'></center></pre></bdo></b><th id='FPkKR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='FPkKR'><tfoot id='FPkKR'></tfoot><dl id='FPkKR'><fieldset id='FPkKR'></fieldset></dl></div>

              • <legend id='FPkKR'><style id='FPkKR'><dir id='FPkKR'><q id='FPkKR'></q></dir></style></legend>

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

                1. <tfoot id='FPkKR'></tfoot>
                  本文介紹了使用 file_get_contents 上傳文件的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

                  問(wèn)題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我意識(shí)到我可以很容易地使用 CURL 做到這一點(diǎn),但我想知道是否可以使用 file_get_contents() 和 http 流上下文將文件上傳到遠(yuǎn)程 Web 服務(wù)器,以及如果是這樣,如何?

                  I realise I can do this with CURL very easily, but I was wondering if it was possible to use file_get_contents() with the http stream context to upload a file to a remote web server, and if so, how?

                  推薦答案

                  首先,multipart Content-Type 的第一條規(guī)則是定義一個(gè)邊界用作每個(gè)部分之間的分隔符(因?yàn)轭櫭剂x,它可以有多個(gè)部分).邊界可以是內(nèi)容正文中未包含的任何字符串.我通常會(huì)使用時(shí)間戳:

                  First of all, the first rule of multipart Content-Type is to define a boundary that will be used as a delimiter between each part (because as the name says, it can have multiple parts). The boundary can be any string that is not contained in the content body. I will usually use a timestamp:

                  define('MULTIPART_BOUNDARY', '--------------------------'.microtime(true));
                  

                  一旦定義了邊界,就必須將它與 Content-Type 標(biāo)頭一起發(fā)送,以告訴網(wǎng)絡(luò)服務(wù)器期望的分隔符:

                  Once your boundary is defined, you must send it with the Content-Type header to tell the webserver what delimiter to expect:

                  $header = 'Content-Type: multipart/form-data; boundary='.MULTIPART_BOUNDARY;
                  

                  完成后,您必須構(gòu)建與 HTTP 規(guī)范和您發(fā)送的標(biāo)頭相匹配的適當(dāng)內(nèi)容正文.如您所知,從表單發(fā)布文件時(shí),您通常會(huì)有一個(gè)表單字段名稱.我們將定義它:

                  Once that is done, you must build a proper content body that matches the HTTP specification and the header you sent. As you know, when POSTing a file from a form, you will usually have a form field name. We'll define it:

                  // equivalent to <input type="file" name="uploaded_file"/>
                  define('FORM_FIELD', 'uploaded_file'); 
                  

                  然后我們構(gòu)建內(nèi)容主體:

                  Then we build the content body:

                  $filename = "/path/to/uploaded/file.zip";
                  $file_contents = file_get_contents($filename);    
                  
                  $content =  "--".MULTIPART_BOUNDARY."
                  ".
                              "Content-Disposition: form-data; name="".FORM_FIELD.""; filename="".basename($filename).""
                  ".
                              "Content-Type: application/zip
                  
                  ".
                              $file_contents."
                  ";
                  
                  // add some POST fields to the request too: $_POST['foo'] = 'bar'
                  $content .= "--".MULTIPART_BOUNDARY."
                  ".
                              "Content-Disposition: form-data; name="foo"
                  
                  ".
                              "bar
                  ";
                  
                  // signal end of request (note the trailing "--")
                  $content .= "--".MULTIPART_BOUNDARY."--
                  ";
                  

                  如您所見(jiàn),我們正在發(fā)送帶有 form-data 配置的 Content-Disposition 標(biāo)頭以及 name 參數(shù)(表單字段名稱)和 filename 參數(shù)(原始文件名).如果您想正確填充 $_FILES[]['type'] 東西,那么發(fā)送帶有正確 MIME 類型的 Content-Type 標(biāo)頭也很重要.

                  As you can see, we're sending the Content-Disposition header with the form-data disposition, along with the name parameter (the form field name) and the filename parameter (the original filename). It is also important to send the Content-Type header with the proper MIME type, if you want to correctly populate the $_FILES[]['type'] thingy.

                  如果您有多個(gè)文件要上傳,您只需使用 $content 位重復(fù)該過(guò)程,當(dāng)然,每個(gè)文件都有不同的 FORM_FIELD.

                  If you had multiple files to upload, you just repeat the process with the $content bit, with of course, a different FORM_FIELD for each file.

                  現(xiàn)在,構(gòu)建上下文:

                  $context = stream_context_create(array(
                      'http' => array(
                            'method' => 'POST',
                            'header' => $header,
                            'content' => $content,
                      )
                  ));
                  

                  并執(zhí)行:

                  file_get_contents('http://url/to/upload/handler', false, $context);
                  

                  注意:在發(fā)送二進(jìn)制文件之前無(wú)需對(duì)其進(jìn)行編碼.HTTP 可以很好地處理二進(jìn)制文件.

                  NOTE: There is no need to encode your binary file before sending it. HTTP can handle binary just fine.

                  這篇關(guān)于使用 file_get_contents 上傳文件的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  enable SOAP on PHP(在 PHP 上啟用 SOAP)
                  Get received XML from PHP SOAP Server(從 PHP SOAP 服務(wù)器獲取接收到的 XML)
                  not a valid AllXsd value(不是有效的 AllXsd 值)
                  PHP SoapClient: SoapFault exception Could not connect to host(PHP SoapClient:SoapFault 異常無(wú)法連接到主機(jī))
                  Implementation of P_SHA1 algorithm in PHP(PHP中P_SHA1算法的實(shí)現(xiàn))
                  Sending a byte array from PHP to WCF(將字節(jié)數(shù)組從 PHP 發(fā)送到 WCF)
                      <tbody id='mzCFp'></tbody>
                    <legend id='mzCFp'><style id='mzCFp'><dir id='mzCFp'><q id='mzCFp'></q></dir></style></legend>

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

                        • <i id='mzCFp'><tr id='mzCFp'><dt id='mzCFp'><q id='mzCFp'><span id='mzCFp'><b id='mzCFp'><form id='mzCFp'><ins id='mzCFp'></ins><ul id='mzCFp'></ul><sub id='mzCFp'></sub></form><legend id='mzCFp'></legend><bdo id='mzCFp'><pre id='mzCFp'><center id='mzCFp'></center></pre></bdo></b><th id='mzCFp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='mzCFp'><tfoot id='mzCFp'></tfoot><dl id='mzCFp'><fieldset id='mzCFp'></fieldset></dl></div>
                        • <tfoot id='mzCFp'></tfoot>
                            <bdo id='mzCFp'></bdo><ul id='mzCFp'></ul>
                            主站蜘蛛池模板: 国产 日韩 欧美 在线 | 狠狠干在线 | 精品欧美一区二区三区久久久 | 在线看91 | 久久久久网站 | 国产成人免费在线 | 久久人人网 | 精品国产乱码久久久久久久久 | 99久久免费精品国产免费高清 | 91精品久久久久久久 | 免费成人国产 | 欧产日产国产精品视频 | 在线成人www免费观看视频 | 999视频| 免费一区二区 | 一区二区三区四区免费观看 | 狠狠久| 日韩在线不卡 | 91精品国产一区 | 国产一区二区精品在线 | 国产精品日本一区二区在线播放 | 亚洲欧美在线视频 | 在线成人 | 日韩国产欧美视频 | 久久99国产精一区二区三区 | 欧美午夜剧场 | 成人欧美一区二区三区色青冈 | 国产精品视频网 | 日本a∨精品中文字幕在线 亚洲91视频 | 中文字幕 在线观看 | 亚洲综合在 | 午夜影院在线观看 | 青娱乐av| 久久精品国产亚洲a | 国产亚洲精品精品国产亚洲综合 | 久久久综合久久 | 中文字幕一区二区三区四区五区 | 亚洲精品免费观看 | 一区二区三区在线 | 亚洲国产精品一区二区www | 美女艹b|