hi i want to restore the documents that i save in the database with base64 format and copy into laravel
storage
file folder. this is because my server get a crash.
so here is my code to restore the document from database table into folder in application server. every user have uniq id (id_pra) and i used that id as a folder name in /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));
}
}
}
i try in local, everything is work, but in production i got this error
PHP Fatal error: 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)
i have already change the memory_limit
in php.ini
from 124M
to 2048M
, but still get the same error. i wanna try to change into -1, but the IT security did'nt allow that. anyone know what is the other solution?
i used redhat and php 7.4, and laravel