我正在将图像文件保存到磁盘。之后,我创建一个 ZIP 并下载它。在本地主机上一切正常。
在实时服务器上,我得到:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator at [email protected] to inform them of the time this error occurred, and the actions you performed just before this error.
More information about this error may be available in the server error log.
如果我想将图像保存到存储中,则会发生错误:
$user = DB::connection('mysql_live')->table('users')->where('id', $userid)->first();
Storage::disk('gdpr')->put($user->picture, file_get_contents(env('AVATAR_PHOTO_SRC') . $user->picture));
env('AVATAR_PHOTO_SRC')
是图像的绝对路径,例如: https://example.com/uploads/thumb/
没有创建日志文件。而且压缩包的大小不到 1MB,图像更小。
这里发生了什么?
编辑
$user->picture
是文件名。例如:example.jpg
。
该文件确实存在并且可以在例如浏览器中打开。记住在本地主机上一切正常。
编辑
我找到了一个登录try,catch:
file_get_contents(): https:// wrapper is disabled in the server configuration by allow_url_fopen=0
编辑
PHP ini 不能在共享服务器上修改。我需要另一种方式来存储图像。
这是 curl 解决方案,对我有用:
$c = curl_init();
curl_setopt($c, CURLOPT_URL, env('AVATAR_PHOTO_SRC') . $user->picture);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($c, CURLOPT_CAINFO, Storage::disk('other')->path("cacert-2020-01-01.pem"));
$img = curl_exec($c);
$httpCode_post = curl_getinfo($c, CURLINFO_HTTP_CODE);
$cerror_post = curl_error($c);
curl_close($c);
Storage::disk('gdpr')->put($user->picture, $img);
您可以设置CURLOPT_SSL_VERIFYPEER
为 false 则不需要证书的步骤。
但我建议你添加证书。它超级容易。只需在此处下载并将其保存在您的存储中的某个位置。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句