Commit 0a4997dfc9ac1650e569ccb4185755e735bfd9a5

Authored by Arsisakarn Srilatanart
1 parent eb9d1daf
Exists in master

เพิ่มการแก้ชื่อไฟล์ที่ php แล้ว return ชื่อไฟล์ใหม่กลับมาใส่ hidden ใน form (หลั…

…งจาก upload เสร็จ ลองกด submit เพื่อดูค่าที่ POST)
Showing 3 changed files with 33 additions and 7 deletions   Show diff stats
dragndrop.html
... ... @@ -18,11 +18,14 @@
18 18 </head>
19 19 <body>
20 20  
21   -<form id="form" method="post" action="#">
  21 +<form id="form" method="post" action="dump.php">
22 22 <div id="uploader">
23 23 <p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
24 24 </div>
25 25 <br />
  26 + <div id="filelist">
  27 +
  28 + </div>
26 29 <input type="submit" value="Submit" />
27 30 </form>
28 31  
... ... @@ -83,7 +86,17 @@
83 86  
84 87 prevent_duplicates: true,
85 88  
86   - autostart: true
  89 + autostart: true,
  90 +
  91 + init: {
  92 + 'FileUploaded': function(up, file, info) {
  93 + var obj = JSON.parse(info.response);
  94 + //console.log(obj);
  95 + //console.log(obj.cleanFileName);
  96 + document.getElementById('filelist').innerHTML += '<input type="hidden" name="imgName[]" value="' + obj.cleanFileName + '">';
  97 + }
  98 +
  99 + }
87 100  
88 101 });
89 102  
... ...
dump.php
... ... @@ -10,7 +10,7 @@
10 10  
11 11 <p>Shows the form items posted.</p>
12 12  
13   -<table>
  13 +<table border="1">
14 14 <tr>
15 15 <th>Name</th>
16 16 <th>Value</th>
... ... @@ -18,7 +18,17 @@
18 18 <?php $count = 0; foreach ($_POST as $name => $value) { ?>
19 19 <tr class="<?php echo $count % 2 == 0 ? 'alt' : ''; ?>">
20 20 <td><?php echo htmlentities(stripslashes($name)) ?></td>
  21 + <?php if (!is_array($value)) { ?>
21 22 <td><?php echo nl2br(htmlentities(stripslashes($value))) ?></td>
  23 + <?php } else { ?>
  24 + <?php
  25 + echo '<td><ul>';
  26 + foreach($value as $key => $subval) {
  27 + echo "<li>[$key] => " . nl2br(htmlentities(stripslashes($subval))) . '</li>';
  28 + }
  29 + echo '</ul></td>';
  30 + ?>
  31 + <?php } //if ?>
22 32 </tr>
23 33 <?php } ?>
24 34 </table>
... ...
upload.php
... ... @@ -35,7 +35,7 @@ if ($_SERVER[&#39;REQUEST_METHOD&#39;] == &#39;OPTIONS&#39;) {
35 35 @set_time_limit(5 * 60);
36 36  
37 37 // Uncomment this one to fake upload time
38   -// usleep(5000);
  38 + usleep(5000);
39 39  
40 40 // Settings
41 41 //$targetDir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
... ... @@ -59,7 +59,10 @@ if (isset($_REQUEST[&quot;name&quot;])) {
59 59 $fileName = uniqid("file_");
60 60 }
61 61  
62   -$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName . date("YmdHis");
  62 +// change file name if you want to here
  63 +$fileName = date("YmdHis") . '_' . $fileName;
  64 +
  65 +$filePath = $targetDir . DIRECTORY_SEPARATOR . $fileName;
63 66  
64 67 // Chunking might be enabled
65 68 $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
... ... @@ -86,7 +89,7 @@ if ($cleanupTargetDir) {
86 89 }
87 90 }
88 91 closedir($dir);
89   -}
  92 +}
90 93  
91 94  
92 95 // Open temp file
... ... @@ -123,4 +126,4 @@ if (!$chunks || $chunk == $chunks - 1) {
123 126 }
124 127  
125 128 // Return Success JSON-RPC response
126   -die('{"jsonrpc" : "2.0", "result" : null, "id" : "id"}');
  129 +die('{"jsonrpc" : "2.0", "result" : null, "id" : "id", "cleanFileName" : "'.$fileName.'"}');
... ...