mirror of
https://github.com/prasathmani/tinyfilemanager
synced 2024-06-08 08:52:23 +02:00
Chunked file upload
Removes any PHP or server-side file-upload limits by using file chunks
This commit is contained in:
parent
bc9096fad3
commit
4c633ec299
|
@ -2,6 +2,7 @@
|
|||
//Default Configuration
|
||||
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"calc_folder":false,"theme":"light"}';
|
||||
|
||||
|
||||
/**
|
||||
* H3K | Tiny File Manager V2.4.6
|
||||
* CCP Programmers | ccpprogrammers@gmail.com
|
||||
|
@ -850,6 +851,9 @@ if (isset($_GET['dl'])) {
|
|||
// Upload
|
||||
if (!empty($_FILES) && !FM_READONLY) {
|
||||
$override_file_name = false;
|
||||
$chunkIndex = $_POST['dzchunkindex'];
|
||||
$chunkTotal = $_POST['dztotalchunkcount'];
|
||||
|
||||
$f = $_FILES;
|
||||
$path = FM_ROOT_PATH;
|
||||
$ds = DIRECTORY_SEPARATOR;
|
||||
|
@ -883,7 +887,7 @@ if (!empty($_FILES) && !FM_READONLY) {
|
|||
$fullPath = $path . '/' . str_replace("./","_",$_REQUEST['fullpath']);
|
||||
$folder = substr($fullPath, 0, strrpos($fullPath, "/"));
|
||||
|
||||
if(file_exists ($fullPath) && !$override_file_name) {
|
||||
if(file_exists ($fullPath) && !$override_file_name && !$chunks) {
|
||||
$ext_1 = $ext ? '.'.$ext : '';
|
||||
$fullPath = str_replace($ext_1, '', $fullPath) .'_'. date('ymdHis'). $ext_1;
|
||||
}
|
||||
|
@ -894,8 +898,44 @@ if (!empty($_FILES) && !FM_READONLY) {
|
|||
umask($old);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (empty($f['file']['error']) && !empty($tmp_name) && $tmp_name != 'none' && $isFileAllowed) {
|
||||
if (move_uploaded_file($tmp_name, $fullPath)) {
|
||||
if ($chunkTotal){
|
||||
$out = @fopen("{$fullPath}.part", $chunkIndex == 0 ? "wb" : "ab");
|
||||
if ($out) {
|
||||
$in = @fopen($tmp_name, "rb");
|
||||
if ($in) {
|
||||
while ($buff = fread($in, 4096)) { fwrite($out, $buff); }
|
||||
} else {
|
||||
$response = array (
|
||||
'status' => 'error',
|
||||
'info' => "failed to open output stream"
|
||||
);
|
||||
}
|
||||
@fclose($in);
|
||||
@fclose($out);
|
||||
@unlink($tmp_name);
|
||||
|
||||
$response = array (
|
||||
'status' => 'success',
|
||||
'info' => "file upload successful",
|
||||
'fullPath' => $fullPath
|
||||
);
|
||||
} else {
|
||||
$response = array (
|
||||
'status' => 'error',
|
||||
'info' => "failed to open output stream"
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ($chunkIndex == $chunkTotal - 1) {
|
||||
rename("{$fullPath}.part", $fullPath);
|
||||
}
|
||||
|
||||
} else if (move_uploaded_file($tmp_name, $fullPath)) {
|
||||
// Be sure that the file has been uploaded
|
||||
if ( file_exists($fullPath) ) {
|
||||
$response = array (
|
||||
|
@ -1181,7 +1221,6 @@ if (isset($_GET['upload']) && !FM_READONLY) {
|
|||
return '';
|
||||
}
|
||||
?>
|
||||
|
||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.5.1/min/dropzone.min.css" rel="stylesheet">
|
||||
<div class="path">
|
||||
|
||||
|
@ -1225,8 +1264,14 @@ if (isset($_GET['upload']) && !FM_READONLY) {
|
|||
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.5.1/min/dropzone.min.js"></script>
|
||||
<script>
|
||||
Dropzone.options.fileUploader = {
|
||||
chunking: true,
|
||||
chunkSize: 10000000,
|
||||
forceChunking: true,
|
||||
retryChunks: true,
|
||||
retryChunksLimit: 3,
|
||||
parallelUploads: 1, // does not support more than 1!
|
||||
timeout: 120000,
|
||||
maxFilesize: <?php echo MAX_UPLOAD_SIZE; ?>,
|
||||
maxFilesize: 10000000000,
|
||||
acceptedFiles : "<?php echo getUploadExt() ?>",
|
||||
init: function () {
|
||||
this.on("sending", function (file, xhr, formData) {
|
||||
|
@ -1237,9 +1282,11 @@ if (isset($_GET['upload']) && !FM_READONLY) {
|
|||
});
|
||||
}).on("success", function (res) {
|
||||
let _response = JSON.parse(res.xhr.response);
|
||||
|
||||
if(_response.status == "error") {
|
||||
toast(_response.info);
|
||||
}
|
||||
|
||||
}).on("error", function(file, response) {
|
||||
toast(response);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue