文件上传PHP参考代码.txt 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ==============此代码仅供参考======================
  2. =====php如何获取文件数据以及计算MD5Code=======
  3. php实例代码如下:
  4. $len = strlen($this->params['biz_content']['fileData']);
  5. $bytes = array();
  6. for($i=0;$i<$len;$i++) {
  7. if(ord($this->params['biz_content']['fileData'][$i]) >= 128){
  8. $byte = ord($this->params['biz_content']['fileData'][$i]) - 256;
  9. }else{
  10. $byte = ord($this->params['biz_content']['fileData'][$i]);
  11. }
  12. $bytes[] = $byte;
  13. }
  14. $this->params['biz_content']['fileData'] = $bytes;//implode(',', $bytes);
  15. public function psbcFileUpload(){
  16. $path = 'G:\guiyaun\20210506114611.jpg';
  17. //方法一:
  18. // $this->params['biz_content']['fileData'] = file_get_contents($path);
  19. // $len = strlen($this->params['biz_content']['fileData']);
  20. // $bytes = array();
  21. // for($i=0;$i<$len;$i++) {
  22. // if(ord($this->params['biz_content']['fileData'][$i]) >= 128){
  23. //
  24. // $byte = ord($this->params['biz_content']['fileData'][$i]) - 256;
  25. // }else{
  26. // $byte = ord($this->params['biz_content']['fileData'][$i]);
  27. // }
  28. // $bytes[] = $byte;
  29. // }
  30. //方法二:
  31. $byteArray = unpack("c*",file_get_contents($path));
  32. foreach ($byteArray as $k=>$v){
  33. $bytes[] = $v;
  34. }
  35. //方法二end
  36. $wx_data["acsMerNo"] = HAO_YI_LIAN_ACS_MER_NO;//业务商户号
  37. $wx_data["fileName"] = '20210506114611';//文件名称
  38. $wx_data["fileType"] = 'jpg';//文件类型
  39. // $wx_data["md5Code"] = hash_file('md5',$path);
  40. $wx_data["md5Code"] = md5_file($path);
  41. $wx_data["fileData"] = $bytes;//文件转换成byte数组
  42. // $wx_data .='&';
  43. $haoYiLian = Lib_Haoyilian_Haoyilian::init();
  44. $wx_order = $haoYiLian->apiRequest("gnete.psbc.electronic.PsbcFile", "upload", $wx_data);
  45. dump($wx_order);
  46. }