By default, KoolUploader saves your uploaded files to targetFolder for you.
However, in some cases, you want to custom the way of handling file, for example: changing file name when save, recording file information to database, checking a file content to decide whether the file is allowed to upload and so on.
KoolUploader does allow you to set your own customized file handling function.
To use this feature you need to create your own function, and assign the funcFileHandle property of KoolUpoadHandler's instance to that function.
You may have a look at Handle.php for more details.
<?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,doc,pdf,txt";
$kul->progressTracking = true;
$kul->maxFileSize = 512*1024; //500KB
?>
<form id="form1" method="post">
<?php echo $koolajax->Render();?>
<?php echo $kul->Render();?>
<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->allowedExtension = "gif,jpg,doc,pdf,txt";
function custom_upload_handle(&$file)
{
//Process saving file with $file information
//$file["name"] : Name of file
//$file["tmp_name"] : Temporary name(path)
//$file["size"] : Size of file
//$file["type"] : Type of file
//$file["error"] : Error if any
if (move_uploaded_file($file["tmp_name"], "../../Temp/".$file["name"]))
{
// success, return true
return true;
}
else
{
//Fail to save file, return false
return false;
}
}
$kulhandle->funcFileHandle = custom_upload_handle;
//Call the handle function to handle the request from client
echo $kulhandle->handleUpload();
?>