-
Notifications
You must be signed in to change notification settings - Fork 201
/
Copy pathExampleAPINew.php
81 lines (70 loc) · 1.83 KB
/
ExampleAPINew.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
/**
* Created by PhpStorm.
* @author domenico [email protected] / [email protected]
* Date: 15/05/14
* Time: 19.28
*
*/
/*
*
* The post with curl will produce this output on the Matecat Side
*
* //var_export( $POST );
* $_POST = array (
* 'project_name' => 'MyProject',
* 'source_lang' => 'en-US',
* 'target_lang' => 'fr-FR',
* 'action' => 'New',
* );
*
* //var_export( $_FILES );
* $_FILES = array (
* 'fileUpload' =>
* array (
* 'name' => 'File_001.odt.sdlxliff',
* 'type' => 'application/octet-stream',
* 'tmp_name' => '/tmp/phpVzKBIM',
* 'error' => 0,
* 'size' => 157380,
* ),
* 'fileUpload1' =>
* array (
* 'name' => 'File_02.doc.sdlxliff',
* 'type' => 'application/octet-stream',
* 'tmp_name' => '/tmp/phpSe1fvB',
* 'error' => 0,
* 'size' => 1198013,
* ),
* );
*
*/
/**
* Array o files with absolute path
* @var $files array
*/
$files = array( '/home/myUser/Documents/File_001.odt.sdlxliff', '/home/myUser/Documents/File_02.doc.sdlxliff' );
/**
* Configure your matecat Url
*
* @var $url string
*/
$url = 'http://matecat.local/api/new';
/*******************************/
$data = array();
$n = sizeof( $files );
$data[ 'project_name' ] = 'MyProject';
$data[ 'source_lang' ] = 'en-US';
$data[ 'target_lang' ] = 'fr-FR';
for ( $i = 0; $i < $n; $i++ ) {
$data[ 'fileUpload' . $i ] = "@" . $files[ $i ];
}
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data );
$response = curl_exec( $ch );
var_export( $response );
//{"status":"OK","message":"Success","id_project":"5655","project_pass":"8b07f5ce98ce"}