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

write.php (877B)


      1 <?php
      2 
      3 function write_note(
      4     string $user,
      5     string $category,
      6     string $filename,
      7     string $content
      8 ) {
      9 
     10     /* Create full file path name */
     11     $dirpath = $GLOBALS["data_dir"] . "/" . $user . "/" . $category;
     12     $filepath = $dirpath . "/" . $filename;
     13 
     14     /* create user directory if it does not exist */
     15     if (opendir($dirpath) === false) {
     16         mkdir(
     17             $dirpath, /* directory */
     18             0770, /* Permissions: rwxrwx--- */
     19             true /* recursive */
     20         );
     21     }
     22 
     23     /* create file-handle */
     24     $file = fopen(
     25         $filepath,
     26         "w"
     27     );
     28     if ($file === false) {
     29         return $file;
     30     }
     31 
     32     /* Write to file */
     33     $bytes = fwrite(
     34         $file,
     35         $content
     36     );
     37 
     38     /* close file-handle */
     39     fclose($file);
     40 
     41     /* return "true" on success and "false" otherwise */
     42     return $bytes !== false;
     43 
     44 }
     45 
     46 ?>