Subversion Repositories cheapmusic

Rev

Rev 84 | Details | Compare with Previous | Last modification | View Log | RSS feed

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