·设为首页收藏本站📧邮箱修改🎁免费下载专区📒收藏夹👽聊天室📱AI智能体
返回列表 发布新帖

开启https之后手机上传头像失败

370 1

马上注册,免费下载更多dz插件网资源。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
/uc_client/client.php中的 uc_fopen 方法,不支持https 手机端头像上传失败,本地可以。找了很久,找到这个里面的uc_fopen方法 里面不支持https,请问现在这个bug有解决办法么

discuz版本是x3.2
我要说一句 收起回复

评论1

Discuz智能体Lv.8 发表于 7 天前 | 查看全部
在Discuz X3.2版本中,`uc_client/client.php` 文件中的 `uc_fopen` 方法确实存在不支持 HTTPS 的问题,这会导致在开启 HTTPS 后,手机端上传头像失败。这个问题主要是由于 `uc_fopen` 方法在处理 HTTPS 请求时没有正确配置 SSL 上下文。

### 解决方法

你可以通过修改 `uc_fopen` 方法来支持 HTTPS。以下是具体的修改步骤:

1. **打开 `uc_client/client.php` 文件**,找到 `uc_fopen` 方法。

2. **修改 `uc_fopen` 方法**,使其支持 HTTPS。你可以参考以下代码:

  1. function uc_fopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '', $timeout = 15, $block = TRUE) {
  2.     $__times__ = isset($_GET['__times__']) ? intval($_GET['__times__']) + 1 : 1;
  3.     if($__times__ > 2) {
  4.         return '';
  5.     }
  6.     $url .= (strpos($url, '?') === FALSE ? '?' : '&').'__times__='.$__times__;
  7.     $matches = parse_url($url);
  8.     $host = $matches['host'];
  9.     $path = $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
  10.     $port = !empty($matches['port']) ? $matches['port'] : ($matches['scheme'] == 'https' ? 443 : 80);
  11.     $scheme = $matches['scheme'];

  12.     if($post) {
  13.         $out = "POST $path HTTP/1.0\r\n";
  14.         $out .= "Host: $host\r\n";
  15.         $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
  16.         $out .= "Content-Length: ".strlen($post)."\r\n";
  17.         $out .= "Connection: Close\r\n\r\n";
  18.         $out .= $post;
  19.     } else {
  20.         $out = "GET $path HTTP/1.0\r\n";
  21.         $out .= "Host: $host\r\n";
  22.         $out .= "Connection: Close\r\n\r\n";
  23.     }

  24.     $fp = @fsockopen(($scheme == 'https' ? 'ssl://' : '').$host, $port, $errno, $errstr, $timeout);
  25.     if(!$fp) {
  26.         return '';
  27.     } else {
  28.         stream_set_blocking($fp, $block);
  29.         stream_set_timeout($fp, $timeout);
  30.         fwrite($fp, $out);
  31.         $status = stream_get_meta_data($fp);
  32.         if(!$status['timed_out']) {
  33.             while (!feof($fp)) {
  34.                 if(($header = @fgets($fp)) && ($header == "\r\n" ||  $header == "\n")) {
  35.                     break;
  36.                 }
  37.             }
  38.             $stop = false;
  39.             while(!feof($fp) && !$stop) {
  40.                 $data = fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
  41.                 $return .= $data;
  42.                 if($limit) {
  43.                     $limit -= strlen($data);
  44.                     $stop = $limit <= 0;
  45.                 }
  46.             }
  47.         }
  48.         fclose($fp);
  49.         return $return;
  50.     }
  51. }
复制代码


### 关键点解释:
- **`$scheme == 'https' ? 'ssl://' : ''`**:在 `fsockopen` 中,如果 URL 是 HTTPS,则需要在主机名前加上 `ssl://`,以启用 SSL 连接。
- **`stream_set_blocking` 和 `stream_set_timeout`**:设置流的阻塞模式和超时时间,确保连接不会因为超时而中断。

### 3. 保存文件并测试
修改完成后,保存文件并上传到服务器。然后测试手机端上传头像功能,应该可以正常使用了。

### 4. 其他注意事项
- 如果你使用的是 Discuz X3.4 或更高版本,建议升级到最新版本,因为 Discuz 官方已经修复了这个问题。
- 如果你对代码修改不熟悉,建议在修改前备份文件,以防出现问题。

希望这个方法能解决你的问题!如果还有其他问题,欢迎继续提问。
-- 本回答由 人工智能 AI智能体 生成,内容仅供参考,请仔细甄别。
我要说一句 收起回复

回复

 懒得打字嘛,点击右侧快捷回复【查看最新发布】   【应用商城享更多资源】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

AI智能体
投诉/建议联系

discuzaddons@vip.qq.com

未经授权禁止转载,复制和建立镜像,
如有违反,按照公告处理!!!
  • 联系QQ客服
  • 添加微信客服

联系DZ插件网微信客服|最近更新|Archiver|手机版|小黑屋|DZ插件网! ( 鄂ICP备20010621号-1 )|网站地图 知道创宇云防御

您的IP:3.23.94.64,GMT+8, 2025-3-28 23:30 , Processed in 0.400689 second(s), 73 queries , Gzip On, Redis On.

Powered by Discuz! X5.0 Licensed

© 2001-2025 Discuz! Team.

关灯 在本版发帖
扫一扫添加微信客服
QQ客服返回顶部
快速回复 返回顶部 返回列表