Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jimmyy
authored and
Jimmyy
committed
Jun 13, 2011
0 parents
commit 428a399
Showing
36 changed files
with
906 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
h1. Playframework plUpload module | ||
|
||
h2. Installation | ||
|
||
Add to your application.conf : | ||
|
||
bc.. module.plupload=${play.path}/modules/plupload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* | ||
* Rewriting of the upload.php file in java | ||
* | ||
* PlayFramework version 1.2.1 | ||
* | ||
* @package controllers.upload | ||
* @author JŽrŽmie Robert <mystheme@free.fr> | ||
* @see plupload | ||
* | ||
*/ | ||
package controllers.plupload; | ||
|
||
import java.io.File; | ||
import java.util.*; | ||
import play.*; | ||
import play.mvc.*; | ||
import play.mvc.Http.Response; | ||
|
||
public class plUpload extends Controller { | ||
|
||
static String targetDir = "../uploads/"; | ||
|
||
public static void index() { | ||
render(); | ||
} | ||
|
||
public static void dump() { | ||
int count = 0; | ||
Map<String, String[]> map = params.all(); | ||
render(map); | ||
} | ||
|
||
public static String upload(String name, File file) { | ||
Response response = Response.current(); | ||
response.setHeader("Server", "Web Server"); | ||
response.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); | ||
response.setHeader("Pragma", "no-cache"); | ||
response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate"); | ||
int chunk = (params.get("chunk") != null) ? Integer.valueOf(params.get("chunk")) : 0; | ||
String chunks = params.get("chunks"); | ||
String filename = (params.get("name") != null) ? params.get("name") : ""; | ||
|
||
System.out.println("chunk : " + chunk); | ||
System.out.println("chunks : " + chunks); | ||
System.out.println("filename : " + filename); | ||
|
||
// Clean the fileName for security reasons | ||
filename = filename.replaceAll("/[^\\w\\._]+/", ""); | ||
|
||
// Make sure the fileName is unique but only if chunking is disabled | ||
File f = new File(targetDir.concat(System.getProperty("file.separator")).concat(filename)); | ||
if (chunk < 2 && f.exists()) { | ||
int ext = filename.lastIndexOf("."); | ||
String fileName_a = filename.substring(0, ext); | ||
String fileName_b = filename.substring(ext); | ||
File test = new File(targetDir.concat(System.getProperty("file.separator")).concat(fileName_a).concat("_").concat(fileName_b)); | ||
int count = 1; | ||
while (test.exists()) { | ||
count++; | ||
} | ||
filename = fileName_a + "_" + count + fileName_b; | ||
System.out.println("filename : " + filename); | ||
} | ||
// Create target dir | ||
File t = new File(targetDir); | ||
if (!t.exists()) { | ||
t.mkdir(); | ||
} | ||
|
||
// Look for the content type header | ||
String contentType = response.getHeader("Content-Type"); | ||
System.out.println("contentType : " + contentType); | ||
// Handle non multipart uploads older WebKit versions didn't support multipart in HTML5 | ||
if (contentType != null && contentType.contains("multipart") != false) { | ||
// Open temp file | ||
File out = new File(targetDir.concat(System.getProperty("file.separator")).concat(filename)); | ||
if (out != null) { | ||
// Read binary input stream and append it to temp file | ||
// $in = fopen($_FILES['file']['tmp_name'], "rb"); | ||
if (file != null) { | ||
System.out.println("rename " + file.getAbsolutePath() + " to " + out.getAbsolutePath()); | ||
file.renameTo(out); | ||
} else { | ||
System.out.println("{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 101, \"message\": \"Failed to open input stream.\"}, \"id\" : \"id\"}"); | ||
return "{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 102, \"message\": \"Failed to open output stream.\"}, \"id\" : \"id\"}"; | ||
} | ||
|
||
} else { | ||
System.out.println("{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 102, \"message\": \"Failed to open output stream.\"}, \"id\" : \"id\"}"); | ||
return "{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 102, \"message\": \"Failed to open output stream.\"}, \"id\" : \"id\"}"; | ||
} | ||
|
||
} else { | ||
// Open temp file | ||
File out = new File(targetDir.concat(System.getProperty("file.separator")).concat(filename)); | ||
// $out = fopen($targetDir.DIRECTORY_SEPARATOR.$fileName, $chunk == 0 ? "wb" : "ab"); | ||
if (out != null) { | ||
if (file != null) { | ||
System.out.println("rename " + file.getAbsolutePath() + " to " + out.getAbsolutePath()); | ||
file.renameTo(out); | ||
} else { | ||
System.out.println("{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 101, \"message\": \"Failed to open input stream.\"}, \"id\" : \"id\"}"); | ||
return "{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 101, \"message\": \"Failed to open input stream.\"}, \"id\" : \"id\"}"; | ||
} | ||
|
||
} else { | ||
System.out.println("{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 102, \"message\": \"Failed to open output stream\"}, \"id\" : \"id\"}"); | ||
return "{\"jsonrpc\" : \"2.0\", \"error\" : {\"code\": 102, \"message\": \"Failed to open output stream\"}, \"id\" : \"id\"}"; | ||
} | ||
} | ||
|
||
// Return JSON-RPC response | ||
System.out.println("{\"jsonrpc\" : \"2.0\", \"result\" : null, \"id\" : \"id\"}"); | ||
return "{\"jsonrpc\" : \"2.0\", \"result\" : null, \"id\" : \"id\"}"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<table> | ||
<tr> | ||
<th>Name</th> | ||
<th>Value</th> | ||
</tr> | ||
#{list items:map, as:'m'} | ||
<tr> | ||
<td>${m.key}</td> | ||
<td>${m.value}</td> | ||
</tr> | ||
#{/list} | ||
</table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#{extends 'main.html' /} | ||
#{set 'moreScripts'} | ||
|
||
<!-- Load Queue widget CSS and jQuery --> | ||
<style type="text/css">@import url(/public/javascripts/plUpload/jquery.plupload.queue/css/jquery.plupload.queue.css);</style> | ||
<script type="text/javascript" src="http://www.google.com/jsapi"></script> | ||
<script type="text/javascript"> | ||
google.load("jquery", "1.3"); | ||
</script> | ||
|
||
<!-- Load plupload and all it's runtimes and finally the jQuery queue widget --> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.html5.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/jquery.plupload.queue/jquery.plupload.queue.js"></script> | ||
|
||
<script type="text/javascript"> | ||
// Convert divs to queue widgets when the DOM is ready | ||
$(function() { | ||
$("#uploader").pluploadQueue({ | ||
// General settings | ||
runtimes : 'html5', | ||
url : 'upload', | ||
max_file_size : '10mb', | ||
chunk_size : '1mb', | ||
unique_names : true, | ||
|
||
// Resize images on clientside if we can | ||
resize : {width : 320, height : 240, quality : 90}, | ||
|
||
// Specify what files to browse for | ||
filters : [ | ||
{title : "Image files", extensions : "jpg,gif,png"}, | ||
{title : "Zip files", extensions : "zip"} | ||
], | ||
|
||
// Flash settings | ||
flash_swf_url : '/plupload/js/plupload.flash.swf', | ||
|
||
// Silverlight settings | ||
silverlight_xap_url : '/plupload/js/plupload.silverlight.xap' | ||
}); | ||
|
||
// Client side form validation | ||
$('form').submit(function(e) { | ||
var uploader = $('#uploader').pluploadQueue(); | ||
|
||
// Validate number of uploaded files | ||
if (uploader.total.uploaded == 0) { | ||
// Files in queue upload them first | ||
if (uploader.files.length > 0) { | ||
// When all files are uploaded submit form | ||
uploader.bind('UploadProgress', function() { | ||
if (uploader.total.uploaded == uploader.files.length) | ||
$('form').submit(); | ||
}); | ||
|
||
uploader.start(); | ||
} else | ||
alert('You must at least upload one file.'); | ||
|
||
e.preventDefault(); | ||
} | ||
}); | ||
}); | ||
</script> | ||
#{/set} | ||
|
||
|
||
|
||
<form method="post" action="dump.php"> | ||
<div id="uploader"> | ||
<p>You browser doesn't have Flash, Silverlight, Gears, BrowserPlus or HTML5 support.</p> | ||
</div> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
#{extends 'main.html' /} | ||
#{set 'moreScripts'} | ||
<link rel="stylesheet" href="/public/javascripts/plUpload/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" media="screen" /> | ||
|
||
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> | ||
<script type="text/javascript" src="http://bp.yahooapis.com/2.4.21/browserplus-min.js"></script> | ||
|
||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.gears.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.silverlight.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.flash.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.browserplus.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.html4.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/plupload.html5.js"></script> | ||
<script type="text/javascript" src="/public/javascripts/plUpload/jquery.plupload.queue/jquery.plupload.queue.js"></script> | ||
#{/set} | ||
|
||
|
||
<form method="post" action="dump.php"> | ||
<h1>Queue widget example</h1> | ||
|
||
<p>Shows the jQuery Plupload Queue widget and under different runtimes.</p> | ||
|
||
<div style="float: left; margin-right: 20px"> | ||
<h3>Flash runtime</h3> | ||
<div id="flash_uploader" style="width: 450px; height: 330px;">You browser doesn't have Flash installed.</div> | ||
|
||
<h3>Gears runtime</h3> | ||
<div id="gears_uploader" style="width: 450px; height: 330px;">You browser doesn't have Gears installed.</div> | ||
</div> | ||
|
||
<div style="float: left; margin-right: 20px"> | ||
<h3>Silverlight runtime</h3> | ||
<div id="silverlight_uploader" style="width: 450px; height: 330px;">You browser doesn't have Silverlight installed.</div> | ||
|
||
<h3>HTML 5 runtime</h3> | ||
<div id="html5_uploader" style="width: 450px; height: 330px;">You browser doesn't support native upload. Try Firefox 3 or Safari 4.</div> | ||
</div> | ||
|
||
<div style="float: left; margin-right: 20px"> | ||
<h3>BrowserPlus runtime</h3> | ||
<div id="browserplus_uploader" style="width: 450px; height: 330px;">You browser doesn't have BrowserPlus installed.</div> | ||
|
||
<h3>HTML 4 runtime</h3> | ||
<div id="html4_uploader" style="width: 450px; height: 330px;">You browser doesn't have HTML 4 support.</div> | ||
</div> | ||
|
||
<br style="clear: both" /> | ||
|
||
<input type="submit" value="Send" /> | ||
</form> | ||
|
||
<script type="text/javascript"> | ||
$(function() { | ||
// Setup flash version | ||
$("#flash_uploader").pluploadQueue({ | ||
// General settings | ||
runtimes : 'flash', | ||
url : '../upload.php', | ||
max_file_size : '10mb', | ||
chunk_size : '1mb', | ||
unique_names : true, | ||
filters : [ | ||
{title : "Image files", extensions : "jpg,gif,png"}, | ||
{title : "Zip files", extensions : "zip"} | ||
], | ||
|
||
// Resize images on clientside if we can | ||
resize : {width : 320, height : 240, quality : 90}, | ||
|
||
// Flash settings | ||
flash_swf_url : '../../js/plupload.flash.swf' | ||
}); | ||
|
||
// Setup gears version | ||
$("#gears_uploader").pluploadQueue({ | ||
// General settings | ||
runtimes : 'gears', | ||
url : 'upload.php', | ||
max_file_size : '10mb', | ||
chunk_size : '1mb', | ||
unique_names : true, | ||
filters : [ | ||
{title : "Image files", extensions : "jpg,gif,png"}, | ||
{title : "Zip files", extensions : "zip"} | ||
], | ||
|
||
// Resize images on clientside if we can | ||
resize : {width : 320, height : 240, quality : 90} | ||
}); | ||
|
||
// Setup silverlight version | ||
$("#silverlight_uploader").pluploadQueue({ | ||
// General settings | ||
runtimes : 'silverlight', | ||
url : 'upload.php', | ||
max_file_size : '10mb', | ||
chunk_size : '1mb', | ||
unique_names : true, | ||
filters : [ | ||
{title : "Image files", extensions : "jpg,gif,png"}, | ||
{title : "Zip files", extensions : "zip"} | ||
], | ||
|
||
// Resize images on clientside if we can | ||
resize : {width : 320, height : 240, quality : 90}, | ||
|
||
// Silverlight settings | ||
silverlight_xap_url : '../../js/plupload.silverlight.xap' | ||
}); | ||
|
||
// Setup html5 version | ||
$("#html5_uploader").pluploadQueue({ | ||
// General settings | ||
runtimes : 'html5', | ||
url : 'upload ', | ||
max_file_size : '10mb', | ||
chunk_size : '1mb', | ||
unique_names : true, | ||
filters : [ | ||
{title : "Image files", extensions : "jpg,gif,png"}, | ||
{title : "Zip files", extensions : "zip"} | ||
], | ||
|
||
// Resize images on clientside if we can | ||
resize : {width : 320, height : 240, quality : 90} | ||
}); | ||
|
||
// Setup browserplus version | ||
$("#browserplus_uploader").pluploadQueue({ | ||
// General settings | ||
runtimes : 'browserplus', | ||
url : 'upload', | ||
max_file_size : '10mb', | ||
chunk_size : '1mb', | ||
unique_names : true, | ||
filters : [ | ||
{title : "Image files", extensions : "jpg,gif,png"}, | ||
{title : "Zip files", extensions : "zip"} | ||
], | ||
|
||
// Resize images on clientside if we can | ||
resize : {width : 320, height : 240, quality : 90} | ||
}); | ||
|
||
// Setup html4 version | ||
$("#html4_uploader").pluploadQueue({ | ||
// General settings | ||
runtimes : 'html4', | ||
url : 'upload', | ||
unique_names : true, | ||
filters : [ | ||
{title : "Image files", extensions : "jpg,gif,png"}, | ||
{title : "Zip files", extensions : "zip"} | ||
] | ||
}); | ||
}); | ||
</script> |
Oops, something went wrong.