Good morning, I have a function that makes an append in a certain line of my xml file.
function addInFile($file, $lineNumber, $content)
{
$fileTemp = "$file.bak";
$currentLine = 0;
$fpRead = fopen($file, 'r');
$fpWrite = fopen($fileTemp, 'w');
try {
if ($fpRead) {
while (($linha = fgets($fpRead)) !== false) {
if ($currentLine == $lineNumber) {
$linha .= $content . PHP_EOL;
}
fwrite($fpWrite, $linha);
$currentLine += 1;
}
}
} catch (\Exception $err) {
echo $err->getMessage() . PHP_EOL;
} finally {
fclose($fpRead);
fclose($fpWrite);
unlink($file);
rename($fileTemp, $file);
}
}
I just need to save my file outside the root of the laravel project, I set the config/filesystem.php
to receive a disk that I called public
'public' => [
'driver' => 'local',
'root' => storage_path('../../../public_html/xmls'),
'visibility' => 'public',
],
My problem is that I do not know how to transform fopen, fgets, fclose, unlink, rename
, etc ... with Storage::disk() do laravel
. If anyone can help me, thank you in advance.