Subversion Repositories cheapmusic

Rev

Rev 65 | Rev 84 | 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);
77 - 19
 
65 - 20
    // If the process is finished, delete the file.
77 - 21
    if ($obj->percent >= 100) {
65 - 22
        @unlink($file);
23
    }
14 - 24
}
25
else {
65 - 26
    echo json_encode(array(
27
        "percent" => null,
28
        "message" => "File Not Found"
29
    ));
14 - 30
}