嗨,我想恢复我保存在数据库中的 base64 格式的文档并复制到laravel
storage
文件夹中。这是因为我的服务器崩溃了。
所以这是我将文档从数据库表恢复到应用程序服务器中的文件夹的代码。每个用户都有 uniq id (id_pra),我使用该 id 作为文件夹名称/public/storage/uploads/file/USERFILEID/
$makedir = User::where('role','9')->get();
foreach ($makedir as $mkdir){
$path = public_path().'/storage/uploads/file/'.$mkdir->id_pra;
$file_user = Document::get();
if(!(file_exists($path))){
File::makeDirectory($path, $mode = 0777, true, true);
foreach($file_user as $file_doc){
if($mkdir->id_pra == $file_doc->id_praapplication){
$image = $file_doc->base64;
$image = str_replace('data:image/png;base64,', '', $image);
$image = str_replace(' ', '+', $image);
$imageName = str_random(10).'.'.'png';
$new_path = public_path().'/storage/uploads/file/'.$mkdir->id_pra;
file_put_contents($new_path.'/'.$file_doc->upload, base64_decode($image));
}
}
}
我在本地尝试,一切正常,但在生产中出现此错误
PHP致命错误: Allowed memory size of 536870912 bytes exhausted (tried to allocate 7743517 bytes) in C:\xampp\htdocs\xxx\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 333 Symfony\Component\Debug\Exception\FatalErrorException : Allowed memory size of 536870912 bytes exhausted (tried to allocate 7743517 bytes)
我已经将memory_limit
inphp.ini
从更改124M
为2048M
,但仍然得到相同的错误。我想尝试更改为 -1,但 IT 安全不允许这样做。有谁知道其他解决方案是什么?
我使用了 redhat 和 php 7.4,并且laravel