php file transfer

  / * * 
     * # + ============================================ ============================ 
     * # | - @name file transfer 
     * # | - @author cq <[email protected] > 
     # * | - @copyright zmtek 2018-11-07 
     * # + ----------------------------------- ------------------------------------- 
     * # | - 1. initialization text 
     * # + = ================================================== ===================== 
     * / 
    public  function upload_file_to_java ( $ path , $ URL , $ JSON ) { 

        $ new_path = $ path ;
         # detecting whether a file exists 
        iF ( !file_exists($new_path)){die();
        }
        # 初始化
        $curl = curl_init();
        # 检测请求版本
        if (class_exists('\CURLFile')) {
            curl_setopt($curl, CURLOPT_SAFE_UPLOAD, true);
            $data = array('Json' => $json, 'File' => new \CURLFile($new_path)); //>=5.5
        } else {
            if (defined( 'CURLOPT_SAFE_UPLOAD' )) { 
                curl_setopt ( $ curl , CURLOPT_SAFE_UPLOAD, to false ); 
            } 
            $ Data = Array ( 'Json' => $ JSON ., 'File' => '@' $ new_path ); // <= 5.5 
        } 

        # request address 
        curl_setopt ( $ curl , CURLOPT_URL to, $ URL );
         # HTTP the POST, this option is set to a nonzero value 
        curl_setopt ( $ curl , CURLOPT_POST,. 1 );
         # in the HTTP "POST" operation. 
        curl_setopt ( $ curl, CURLOPT_POSTFIELDS, $ Data );
         # set if the header information 
        curl_setopt ( $ curl , CURLOPT_RETURNTRANSFER,. 1 );
         # contains a "user-agent" string in the HTTP request header. 
        curl_setopt ( $ curl , CURLOPT_USERAGENT, "the TEST" );
         # is not set timeout 
        curl_setopt ( $ curl , CURLOPT_TIMEOUT, 0 );
         # perform 
        $ Result = the curl_exec ( $ curl );
         # If an error exists 
        IF (curl_errno ( $ curl )) {
             # active trigger an exception 
            $ resultCurl_error = ( $ curl ); 
        } 
        # close the resource 
        curl_close ( $ curl ); 

        # return data 
        return $ Result ; 
    }

Guess you like

Origin www.cnblogs.com/leaf-cq/p/12195533.html