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

read.php (771B)


      1 <?php
      2 
      3 function read_note(
      4     string $user,
      5     string $category,
      6     string $filename,
      7 ) {
      8 
      9     /* Create full file path name */
     10     $dirpath = $GLOBALS["data_dir"] . "/" . $user . "/" . $category;
     11     $filepath = $dirpath . "/" . $filename;
     12 
     13     /* get filesize */
     14     $filesize = filesize($filepath);
     15 
     16     if ($filesize > 0) {
     17 
     18         /* create file-handle */
     19         $file = fopen(
     20             $filepath,
     21             "r"
     22         );
     23 
     24         /* Read from file */
     25         $content = fread($file, $filesize);
     26 
     27         /* close file-handle */
     28         fclose($file);
     29 
     30     } else {
     31 
     32         $content = false;
     33 
     34     }
     35 
     36     /* return content.If reading fails, returns "" */
     37     if ($content === false) {
     38         return "";
     39     } else {
     40         return $content;
     41     }
     42 
     43 }
     44 
     45 ?>