Qi Niu Integrated PHP to upload files ,. Qiniu integrates PHP to upload files. Qiniu supports the remote image capture API. it uses access_key + secret_key + url to generate access_token and adds access_token to the header, then integrate PHP with posturl to upload files,
Qiniu supports the remote image capture API. it uses access_key + secret_key + url to generate access_token, adds access_token to the header, and then uploads the image to the post url. Sample code:
-
- /*
- *
- * @ Desc base64 encoding in the URL safe format
- * @ Param string $ str
- * @ Return string
- */
-
-
- Function urlsafe_base64_encode ($ str ){
- $ Find = array ("+ ","/");
- $ Replace = array ("-","_");
- Return str_replace ($ find, $ replace, base64_encode ($ str ));
- }
-
- /**
- * Generate_access_token
- *
- * @ Desc signature calculation
- * @ Param string $ access_key
- * @ Param string $ secret_key
- * @ Param string $ url
- * @ Param array $ params
- * @ Return string
- */
- Function generate_access_token ($ access_key, $ secret_key, $ url, $ params = ''){
- $ Parsed_url = parse_url ($ url );
- $ Path = $ parsed_url ['path'];
- $ Access = $ path;
- If (isset ($ parsed_url ['query']) {
- $ Access. = "? ". $ Parsed_url ['query'];
- }
- $ Access. = "\ n ";
- If ($ params ){
- If (is_array ($ params )){
- $ Params = http_build_query ($ params );
- }
- $ Access. = $ params;
- }
- $ Digest = hash_hmac ('sha1', $ access, $ secret_key, true );
- Return $ access_key. ':'. urlsafe_base64_encode ($ digest );
- }
-
- /**
- * Test
- */
-
- $ Access_key = '''Your access_key ';
- $ Secret_key = 'Your secret_key ';
-
- $ Fetch = urlsafe_base64_encode ('http: // 203.208.46.200/images/srpr/logo111_png ');
- $ To = urlsafe_base64_encode ('ibeircn: 11.jpg ');
-
- $ Url = 'http: // iovip. qbox. me/fetch/'. $ fetch.'/to/'. $;
-
- $ Access_token = generate_access_token ($ access_key, $ secret_key, $ url );
-
- $ Header [] = 'content-Type: application/json ';
- $ Header [] = 'authorization: qbox'. $ access_token;
-
-
- $ Con = send ('iovip. qbox. me/fetch/'. $ fetch.'/to/'. $ to, $ header );
- Var_dump ($ con );
-
- Function send ($ url, $ header = ''){
- $ Curl = curl_init ($ url );
- Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 );
- Curl_setopt ($ curl, CURLOPT_HEADER, 1 );
- Curl_setopt ($ curl, CURLOPT_HTTPHEADER, $ header );
- Curl_setopt ($ curl, CURLOPT_POST, 1 );
-
- $ Con = curl_exec ($ curl );
-
- If ($ con === false ){
- Echo 'curl ERROR: '. curl_error ($ CURL );
- } Else {
- Return $ con;
- }
- }
- ?>
Source: >
Token, Qiniu supports the API for capturing remote images. use access_key + secret_key + url to generate access_token, add access_token to the header, and then add it to the post url...