Subversion Repositories cheapmusic

Rev

Rev 15 | Rev 65 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14 - 1
<?php
2
// The file has JSON type.
3
header('Content-Type: application/json');
4
 
5
// Prepare the file name from the query string.
15 - 6
if (!preg_match("#^[a-zA-Z0-9_]+$#", $_GET['file'])) {
7
    die;
8
}
9
$file = "../tmp/pb_" . $_GET['file'] . ".txt";
14 - 10
 
11
// Make sure the file is exist.
12
if (file_exists($file)) {
13
  // Get the content and echo it.
14
  $text = file_get_contents($file);
15
  echo $text;
16
 
17
// Convert to JSON to read the status.
18
  $obj = json_decode($text);
20 - 19
// If the process is finished, delete the file.
14 - 20
  if ($obj->percent == 100) {
20 - 21
    @unlink($file);
14 - 22
  }
23
}
24
else {
25
  echo json_encode(array("percent" => null, "message" => "File Not Found"));
26
}