Which users is this plug-in mainly targeted?
1. If you want to be a user who downloads the server, you don’t have enough bandwidth or enough space. How can we do this? Make our website into an intermediate layer, and then upload it to the server, it is actually uploaded to Qiniu Cloud Storage. Downloading is equivalent to downloading in Qiniu, which saves space and bandwidth, which solves the possibility that small spaces cannot be used as download sites!
2. My server is very good, but sometimes the user uploads only a few K speed up. There is a limit of ISP to 64KB, but it cannot reach a few K. This is real. We also use this as the upload server and then use software to download it to the server regularly. This is what a website owner does now.
3. Make a personal document library and let others upload it to my cloud space
Just the example shown in the figure below
Regarding this plug-in, I have to say in JS that the Plupload plug-in is really powerful. There is a problem with being powerful. It is complex. What is complex means customization. Do it yourself and you can implement the functions you want. If you only talk about this plug-in, it would be too difficult. You can refer to the official API. I am just making a Qiniu demo. If you have uploadify in front, you can take a look!
index.php
The code copy is as follows:
<?php
require_once("./qiniu/io.php");
require_once("./qiniu/rs.php");
require_once("./qiniu/fop.php");
$bucket = "space name";
$accessKey = 'APIKEY';
$secretKey = 'APIKEY';
Qiniu_SetKeys($accessKey, $secretKey);
$putPolicy = new Qiniu_RS_PutPolicy($bucket);
$upToken = $putPolicy->Token(null);
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Plupload for QINIU</title>
<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" />
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
<link rel="stylesheet" href="./js/jquery.plupload.queue/css/jquery.plupload.queue.css" type="text/css" />
<script type="text/javascript" src="./js/plupload.full.min.js"></script>
<script type="text/javascript" src="./js/jquery.ui.plupload/jquery.ui.plupload.js"></script>
<script type="text/javascript" src="./js/jquery.plupload.queue/jquery.plupload.queue.js"></script>
</head>
<body style="font: 13px Verdana; background: #eee; color: #333">
<h1>Plupload to QINIU Example</h1>
<div id="uploader">
<p>Your browser doesn't have Flash, Silverlight or HTML5 support.</p>
</div>
<script type="text/javascript">
$(function() {
$("#uploader").pluploadQueue({
//Set type
runtimes: 'html5,flash,silverlight',
//Set the uploaded url
url : 'http://up.qiniu.com/',
multipart: true,
//Set the token that post is passed to Qiniu
multipart_params: {
'token': '<?php echo $upToken; ?>',
},
resize : {width : 800, height : 600, quality : 60}, // Set size
//Modify the post field to Qiniu file
file_data_name: 'file',
//Set some restrictions
filters : {
// Set the size
max_file_size : '10mb',
// The type of upload allowed
mime_types: [
{title : "Image files", extensions : "png,jpeg"},
{title : "RAR files", extensions : "rar,zip,tar.gz"}
]
},
// Set the path to Flash
flash_swf_url : './js/Moxie.swf',
// Set the path to Silverlight
silverlight_xap_url : './js/Moxie.xap',
//Multi-file upload If you upload multiple files, you can remove the comments here
// preinit :{
// UploadFile : function(up,file){
// up.settings.multipart_params.key=file.name;
// }
// },
});
var uploader = $('#uploader').pluploadQueue(); // Get the upload queue
//There are many specific methods for binding FIlesAdded. You can see the official API single file upload method.
uploader.bind('FilesAdded',function(up,files){
//Get file name This is single if multiple files need to be uploaded in a loop
var filename = files[0].name;
var filedata = filename.split(".");
var type = filedata[filedata.length-1];
up.settings.multipart_params.key="<?php echo date('Ymd-His') . '-' . rand(10000,99999);?>"+"."+type;
});
if (uploader.files.length > 0) { // That is to say, if there are still files in the upload queue
uploader.start();
} else {
alert('You have to select a file.');
}
});
</script>
</body>
</html>
Qiniu's products are really good. You can learn from my previous articles, including server backup (LINUX) and uploadify plug-in. Relatively speaking, this JS plug-in is simple, of course, there is also Qiniu's query code. If you have any questions, just ask me.