In this example, you can add a number of files and click Upload button. The list of files will be uploaded sequentially, one file at a time.
Uploading many files simultaneously is great but consume more server power and bandwidth of connection. This will increase the chances of uploading failure if we do not have strong server or users do not have good connection. Sequential uploading is a solution.
<?php
require $KoolControlsFolder."/KoolUploader/kooluploader.php";
require $KoolControlsFolder."/KoolAjax/koolajax.php";
$kul = new KoolUploader("kul");
$kul->scriptFolder = $KoolControlsFolder."/KoolUploader";
$kul->handlePage = "handle.php";
$kul->styleFolder=$KoolControlsFolder."/KoolUploader/styles/default";
$kul->allowedExtension = "gif,jpg,txt,doc,pdf";
$kul->progressTracking = true;
$kul->maxFileSize = 512*1024;
?>
<form id="form1" method="post">
<?php echo $koolajax->Render();?>
<style type="text/css">
.defaultKUL .kulUploadAll
{
display:none;
}
</style>
<?php echo $kul->Render();?>
<script type="text/javascript">
kul.registerEvent("OnUploadDone",function(sender,arg){
var _items = kul.getItems(); //Get all items
for(var i in _items)
{
if(_items[i].getStatus()=="ready")
{
_items[i].upload();
return;
}
}
});
kul.registerEvent("OnBeforeUpload",function(sender,arg){
//Make sure that only one file is uploaded at a time.
//Cancel user click button to upload the file when there is file uploading.
var _items = kul.getItems(); //Get all items
for(var i in _items)
{
if(_items[i].getStatus()=="uploading")
{
return false;
}
}
return true;
});
</script>
<div style="padding-top:20px;">
<i>*Note:</i> Please test uploading with *.txt, *.doc, *.pdf, *.jpg, *.gif ( size < 500KB )
</div>
</form>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
// always modified
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
// HTTP/1.1
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
// HTTP/1.0
header("Pragma: no-cache");
$KoolControlsFolder = "../../../../KoolControls";
require $KoolControlsFolder."/KoolUploader/kooluploader.php";
//Create handle object and edit upload settings.
$kulhandle = new KoolUploadHandler();
$kulhandle->targetFolder = "../../Temp";
$kulhandle->allowedExtension = "gif,jpg,doc,pdf,txt";
//Call the handle function to handle the request from client
echo $kulhandle->handleUpload();
?>