file.php 1.4 KB
Newer Older
Carsten  Rose's avatar
Carsten Rose committed
1
2
3
4
5
6
7
8
<?php
/**
 * Created by PhpStorm.
 * User: crose
 * Date: 4/25/16
 * Time: 8:02 PM
 */

9
10
11
12
13
14
15
namespace qfq;

use qfq;

require_once(__DIR__ . '/../qfq/store/Store.php');
require_once(__DIR__ . '/../qfq/Constants.php');
require_once(__DIR__ . '/../qfq/File.php');
16
17
require_once(__DIR__ . '/../qfq/exceptions/UserFormException.php');
require_once(__DIR__ . '/../qfq/exceptions/CodeException.php');
18
19

/**
20
 * Process File Upload - immediately when the the user selects a file.
21
22
23
24
25
26
27
 * Return JSON encoded answer
 *
 * status: success|error
 * message: <message>
 *
 * Description:
 *
28
 * Upload successful & File accepted by server.
29
30
31
32
33
34
35
36
 *  status = 'success'
 *  message = <message>
 *
 * Upload failed:
 *  status = 'error'
 *  message = <message>
 */

Carsten  Rose's avatar
Carsten Rose committed
37
38
39
$answer = array();

$answer[API_STATUS] = API_ANSWER_STATUS_ERROR;
40
$answer[API_MESSAGE] = '';
Carsten  Rose's avatar
Carsten Rose committed
41
42

try {
43
    try {
Carsten  Rose's avatar
Carsten Rose committed
44

45
        $fileUpload = new File();
Carsten  Rose's avatar
Carsten Rose committed
46

47
        $fileUpload->process();
Carsten  Rose's avatar
Carsten Rose committed
48

49
        $answer[API_MESSAGE] = 'upload: success';
50
//    $answer[API_REDIRECT] = API_ANSWER_REDIRECT_NO;
51
        $answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
Carsten  Rose's avatar
Carsten Rose committed
52

53
54
55
56
57
    } catch (qfq\UserFormException $e) {
        $answer[API_MESSAGE] = $e->formatMessage();
    } catch (qfq\CodeException $e) {
        $answer[API_MESSAGE] = $e->formatMessage();
    }
Carsten  Rose's avatar
Carsten Rose committed
58
59
60
61
62
63
64
} catch (\Exception $e) {
    $answer[API_MESSAGE] = "Generic Exception: " . $e->getMessage();
}

header("Content-Type: application/json");
echo json_encode($answer);