OSDN Git Service

[add]ダンプ・スクリーンショット保存メソッド、存在確認メソッド
authorHabu <habu@users.sourceforge.jp>
Thu, 15 Mar 2018 11:51:29 +0000 (20:51 +0900)
committerHabu <habu@users.sourceforge.jp>
Thu, 15 Mar 2018 11:51:29 +0000 (20:51 +0900)
dump_file.inc

index 8c02ad6..9ab7380 100644 (file)
@@ -5,10 +5,17 @@ class DumpFile
         $this->score_id = $score_id;
     }
 
-    public function show($dir, $ext, $content_type)
+
+    public function get_filename($dir, $ext)
     {
         $dirname = sprintf("%s/%d", $dir, floor($this->score_id / 1000) * 1000);
-        $filename = sprintf("%s/%d.%s.gz", $dirname, $this->score_id, $ext);
+        return sprintf("%s/%d.%s.gz", $dirname, $this->score_id, $ext);
+    }
+
+
+    public function show($dir, $ext, $content_type)
+    {
+        $filename = $this->get_filename($dir, $ext);
 
         if (!file_exists($filename)) {
             http_response_code(404);
@@ -35,6 +42,40 @@ class DumpFile
         }
     }
 
+
+    public function save($dir, $ext, $contents)
+    {
+        if ($outputs === FALSE) return;
+
+        umask(2); // Group書き込み権限許可
+
+        $filename = $this->get_filename($dir, $ext);
+        $dirname = dirname($filename);
+
+        if (!file_exists($dirname)) {
+            mkdir($dirname, 02775, TRUE);
+        }
+
+        $zp = gzopen($filename, "w9");
+
+        foreach ($contents as $line) {
+            gzwrite($zp, $line);
+            gzwrite($zp, "\n");
+        }
+
+        gzclose($zp);
+    }
+
+
+    public function exists($dir, $ext)
+    {
+        $dirname = sprintf("%s/%d", $dir, floor($this->score_id / 1000) * 1000);
+        $filename = sprintf("%s/%d.%s.gz", $dirname, $this->score_id, $ext);
+
+        return file_exists($filename);
+    }
+
+
     private static function browser_accept_encodings()
     {
         if (!isset($_SERVER["HTTP_ACCEPT_ENCODING"])) return [];