Skip to content

Commit fe0f710

Browse files
committed
samples/PhotoAlbum - Display image thumbnail and metadata after upload
1 parent 54e8a60 commit fe0f710

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

samples/PhotoAlbum/upload.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
<script src="lib/jquery.iframe-transport.js"></script>
1616
<script src="lib/jquery.fileupload.js"></script>
1717
<script src="lib/jquery.cloudinary.js"></script>
18+
<script>
19+
$.cloudinary.config("cloud_name", "<?php echo Cloudinary::config_get("cloud_name"); ?>");
20+
</script>
1821
</head>
1922
<body>
2023
<div id="logo">
@@ -57,8 +60,19 @@
5760
<?php
5861
echo cl_image_upload_tag('test', array("tags" => "direct_photo_album"));
5962
?>
63+
<div class="uploaded-info" style="display: none;">
64+
<div class="data"></div>
65+
<div class="image"></div>
66+
</div>
6067
</div>
6168
<script>
69+
function prettydump(obj) {
70+
ret = ""
71+
$.each(obj, function(key, value) {
72+
ret += "<tr><td>" + key + "</td><td>" + value + "</td></tr>";
73+
});
74+
return ret;
75+
}
6276
$('.cloudinary-fileupload')
6377
.fileupload({
6478
dropZone: '#direct_upload',
@@ -72,7 +86,11 @@
7286
.on('cloudinarydone', function (e, data) {
7387
$('.status_value').text('Idle');
7488
$.post('upload_complete.php', data.result);
75-
$('<p/>').text(data.result.public_id).appendTo('#direct_upload');
89+
$('.uploaded-info .data').html(prettydump(data.result));
90+
$('.uploaded-info .image').empty().append($.cloudinary.image(data.result.public_id, {
91+
format: "png", width: 400, height: 300,
92+
}));
93+
$('.uploaded-info').show();
7694
});
7795
</script>
7896
</body>

samples/PhotoAlbum/upload_backend.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,28 @@ function create_photo($file_path) {
88
unlink($file_path);
99
error_log("upload result: " . \PhotoAlbum\ret_var_dump($result));
1010
$photo = \PhotoAlbum\create_photo_model($result);
11-
return $result["public_id"];
11+
return $result;
1212
}
1313

1414
$files = $_FILES["files"];
1515
$files = is_array($files) ? $files : array($files);
16-
$ids = array();
16+
$files_data = array();
1717
foreach ($files["tmp_name"] as $index => $value) {
18-
array_push($ids, create_photo($value));
18+
array_push($files_data, create_photo($value));
1919
}
2020

2121
?>
2222
<html><head><title>Upload succeeded!</title></head>
2323
<body>
2424
<h1>Your photos has been uploaded</h1>
2525
<?php
26-
foreach ($ids as $id) {
27-
echo cl_image_tag($id, $thumbs_params);
26+
foreach ($files_data as $file_data) {
27+
echo "<table>";
28+
foreach ($file_data as $key => $value) {
29+
echo "<tr><td>" . $key . "</td><td>" . $value . "</td></tr>";
30+
}
31+
echo "</table>";
32+
echo cl_image_tag($file_data['public_id'], $thumbs_params);
2833
}
2934
?>
3035
</body>

0 commit comments

Comments
 (0)