pub / rememori

Simple file-based bookmarking and notes application
git clone https://src.jayvii.de/pub/rememori.git
Home | Log | Files | Exports | Refs | README | RSS

commit 6c2a3e575d7f47215934c39e49eb15c2c5149120
parent 7ee55fcd427fc3bc848ca18a6be9607066ca6de9
Author: JayVii <jayvii[AT]posteo[DOT]de>
Date:   Thu, 24 Oct 2024 16:30:58 +0200

feat: add function to write notes

Diffstat:
Alib/write.php | 44++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+), 0 deletions(-)

diff --git a/lib/write.php b/lib/write.php @@ -0,0 +1,44 @@ +/* SPDX-License-Identifier: AGPL-3.0-or-later + * SPDX-FileCopyrightText: 2021-2024 JayVii <jayvii[AT]posteo[DOT]de> + */ + +<?php + +function write_note( + string $user, + string $category, + string $filename, + string $content +) { + + /* Create full file path name */ + $dirpath = "./data/" . $user . "/" . $category; + $filepath = $dirpath . "/" . $filename; + + /* create user directory if it does not exist */ + if (opendir($dirpath) !== false) { + mkdir( + $dirpath, /* directory */ + 0770, /* Permissions: rwxrwx--- */ + true /* recursive */ + ); + } + + /* create file-handle */ + $file = fopen( + $filepath, + "w" + ); + + /* Write to file */ + fwrite( + $file, + $content + ); + + /* return "true" on success */ + return true; + +} + +?>