file.php 1.27 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
 */

Marc Egger's avatar
Marc Egger committed
9
namespace IMATHUZH\Qfq\Api;
10

Marc Egger's avatar
Marc Egger committed
11
require_once(__DIR__ . '/../../vendor/autoload.php');
12

Marc Egger's avatar
Marc Egger committed
13
use IMATHUZH\Qfq\Core\File;
14
15
use IMATHUZH\Qfq\Core\Helper\Path;

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

Carsten  Rose's avatar
Carsten Rose committed
34
35
36
$answer = array();

$answer[API_STATUS] = API_ANSWER_STATUS_ERROR;
37
$answer[API_MESSAGE] = '';
Carsten  Rose's avatar
Carsten Rose committed
38
39

try {
40
    try {
41
        Path::setMainPaths();
42
        $fileUpload = new File();
Carsten  Rose's avatar
Carsten Rose committed
43

44
        $fileUpload->process();
Carsten  Rose's avatar
Carsten Rose committed
45

46
        $answer[API_MESSAGE] = 'upload: success';
47
//    $answer[API_REDIRECT] = API_ANSWER_REDIRECT_NO;
48
        $answer[API_STATUS] = API_ANSWER_STATUS_SUCCESS;
Carsten  Rose's avatar
Carsten Rose committed
49

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

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