Home > Article > Backend Development > Tencent Object Storage PHP practice upload PHP object creation PHP object-oriented exercises PHP json pair
Post the code first
<code><span><?php</span><span>$file_name</span> = <span>'test.jpg'</span>; <span>$upload_url</span> = <span>'web.file.myqcloud.com/files/v1/10039609/wechat/cover/'</span> . <span>$file_name</span>; <span>$exp</span> = time() + <span>600</span>; <span>$sign</span> = <span>'a=10039609&b=wechat&k=AKIDqybsVwxcwSeGYJTsLElPdjgFGa5aPGso&e='</span> . <span>$exp</span> . <span>'&t='</span> . time() . <span>'&r='</span> . rand() . <span>'&f=/10039609/wechat/cover/'</span> . <span>$file_name</span>; <span>$sign</span> = base64_encode(hash_hmac(<span>'SHA1'</span>, <span>$sign</span>, <span>'prbaqNGhrNinShbRWXqfT10wpCFs68hu'</span>, <span>true</span>) . <span>$sign</span>); <span>$post_data</span> = [ <span>'op'</span> => <span>'upload'</span>, <span>'filecontent'</span> => file_get_contents(<span>'https://ss0.bdstatic.com/5aV1bjqh_Q23odCf/static/superman/img/logo_top_ca79a146.png'</span>), <span>// baidu logo</span>]; <span>$header</span> = [ <span>'Content-Type: multipart/form-data'</span>, <span>'Authorization: '</span> . <span>$sign</span>, ]; <span>$ch</span> = curl_init(<span>$upload_url</span>); curl_setopt(<span>$ch</span>, CURLOPT_POST, <span>1</span>); curl_setopt(<span>$ch</span>, CURLOPT_HTTPHEADER, <span>$header</span>); curl_setopt(<span>$ch</span>, CURLOPT_RETURNTRANSFER, <span>1</span>); curl_setopt(<span>$ch</span>, CURLOPT_POSTFIELDS, <span>$post_data</span>); <span>$res</span> = curl_exec(<span>$ch</span>); <span>echo</span><span>'<pre class="brush:php;toolbar:false">'</span>; print_r(json_decode(<span>$res</span>, <span>true</span>));</span></code>').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });
The above introduces the uploading of Tencent Object Storage PHP practice, including PHP and object content. I hope it will be helpful to friends who are interested in PHP tutorials.