/
3-assembly-form-with-jquery-plugin.php
64 lines (56 loc) · 1.87 KB
/
3-assembly-form-with-jquery-plugin.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
<?php
require __DIR__ . '/common/loader.php';
/*
### 3. Integrate the jQuery plugin into the previous example
Integrating the jQuery plugin simply means adding a few lines of JavaScript
to the previous example. Check the HTML comments below to see what changed.
Alternatively, check out [Uppy](https://transloadit.com/docs/sdks/uppy/), our next-gen file uploader for the web.
*/
use transloadit\Transloadit;
$transloadit = new Transloadit([
'key' => 'YOUR_TRANSLOADIT_KEY',
'secret' => 'YOUR_TRANSLOADIT_SECRET',
]);
$response = Transloadit::response();
if ($response) {
echo '<h1>Assembly Status:</h1>';
echo '<pre>';
print_r($response);
echo '</pre>';
exit;
}
$redirectUrl = sprintf('http://%s%s', $_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI']);
echo $transloadit->createAssemblyForm([
'params' => [
'steps' => [
'resize' => [
'robot' => '/image/resize',
'width' => 200,
'height' => 100,
],
],
'redirect_url' => $redirectUrl,
],
]);
?>
<!--
Including the jQuery plugin is as simple as adding jQuery and including the
JS snippet for the plugin. See https://transloadit.com/docs/sdks/jquery-sdk/
-->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
var tlProtocol = (('https:' === document.location.protocol) ? 'https://' : 'http://');
document.write(unescape("%3Cscript src='" + tlProtocol + "assets.transloadit.com/js/jquery.transloadit2.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
$(document).ready(function() {
// Tell the transloadit plugin to bind itself to our form
$('form').transloadit();
});
</script>
<!-- Nothing changed below here -->
<h1>Pick an image to resize</h1>
<form>
<input name="example_upload" type="file">
<input type="submit" value="Upload">
</form>