Subversion Repositories cheapmusic

Rev

Rev 20 | Rev 77 | 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'])) {
65 - 7
    die;
15 - 8
}
9
$file = "../tmp/pb_" . $_GET['file'] . ".txt";
14 - 10
 
11
// Make sure the file is exist.
12
if (file_exists($file)) {
65 - 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);
19
    // If the process is finished, delete the file.
20
    if ($obj->percent == 100) {
21
        @unlink($file);
22
    }
14 - 23
}
24
else {
65 - 25
    echo json_encode(array(
26
        "percent" => null,
27
        "message" => "File Not Found"
28
    ));
14 - 29
}