mirror of
https://github.com/prasathmani/tinyfilemanager
synced 2024-05-08 00:26:36 +02:00
Chunked file upload (#714)
Removes any PHP or server-side file-upload limits by using file chunks
This commit is contained in:
parent
154947ef83
commit
c3a2f1d604
|
@ -2,6 +2,7 @@
|
||||||
//Default Configuration
|
//Default Configuration
|
||||||
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"calc_folder":false,"theme":"light"}';
|
$CONFIG = '{"lang":"en","error_reporting":false,"show_hidden":false,"hide_Cols":false,"calc_folder":false,"theme":"light"}';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* H3K | Tiny File Manager V2.4.6
|
* H3K | Tiny File Manager V2.4.6
|
||||||
* CCP Programmers | ccpprogrammers@gmail.com
|
* CCP Programmers | ccpprogrammers@gmail.com
|
||||||
|
@ -850,6 +851,9 @@ if (isset($_GET['dl'])) {
|
||||||
// Upload
|
// Upload
|
||||||
if (!empty($_FILES) && !FM_READONLY) {
|
if (!empty($_FILES) && !FM_READONLY) {
|
||||||
$override_file_name = false;
|
$override_file_name = false;
|
||||||
|
$chunkIndex = $_POST['dzchunkindex'];
|
||||||
|
$chunkTotal = $_POST['dztotalchunkcount'];
|
||||||
|
|
||||||
$f = $_FILES;
|
$f = $_FILES;
|
||||||
$path = FM_ROOT_PATH;
|
$path = FM_ROOT_PATH;
|
||||||
$ds = DIRECTORY_SEPARATOR;
|
$ds = DIRECTORY_SEPARATOR;
|
||||||
|
@ -882,20 +886,56 @@ if (!empty($_FILES) && !FM_READONLY) {
|
||||||
if ( is_writable($targetPath) ) {
|
if ( is_writable($targetPath) ) {
|
||||||
$fullPath = $path . '/' . basename($_REQUEST['fullpath']);
|
$fullPath = $path . '/' . basename($_REQUEST['fullpath']);
|
||||||
$folder = substr($fullPath, 0, strrpos($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 : '';
|
$ext_1 = $ext ? '.'.$ext : '';
|
||||||
$fullPath = $path . '/' . basename($_REQUEST['fullpath'], $ext_1) .'_'. date('ymdHis'). $ext_1;
|
$fullPath = $path . '/' . basename($_REQUEST['fullpath'], $ext_1) .'_'. date('ymdHis'). $ext_1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!is_dir($folder)) {
|
if (!is_dir($folder)) {
|
||||||
$old = umask(0);
|
$old = umask(0);
|
||||||
mkdir($folder, 0777, true);
|
mkdir($folder, 0777, true);
|
||||||
umask($old);
|
umask($old);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (empty($f['file']['error']) && !empty($tmp_name) && $tmp_name != 'none' && $isFileAllowed) {
|
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
|
// Be sure that the file has been uploaded
|
||||||
if ( file_exists($fullPath) ) {
|
if ( file_exists($fullPath) ) {
|
||||||
$response = array (
|
$response = array (
|
||||||
|
@ -1181,7 +1221,6 @@ if (isset($_GET['upload']) && !FM_READONLY) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.5.1/min/dropzone.min.css" rel="stylesheet">
|
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.5.1/min/dropzone.min.css" rel="stylesheet">
|
||||||
<div class="path">
|
<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 src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.5.1/min/dropzone.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
Dropzone.options.fileUploader = {
|
Dropzone.options.fileUploader = {
|
||||||
|
chunking: true,
|
||||||
|
chunkSize: 10000000,
|
||||||
|
forceChunking: true,
|
||||||
|
retryChunks: true,
|
||||||
|
retryChunksLimit: 3,
|
||||||
|
parallelUploads: 1, // does not support more than 1!
|
||||||
timeout: 120000,
|
timeout: 120000,
|
||||||
maxFilesize: <?php echo MAX_UPLOAD_SIZE; ?>,
|
maxFilesize: 10000000000,
|
||||||
acceptedFiles : "<?php echo getUploadExt() ?>",
|
acceptedFiles : "<?php echo getUploadExt() ?>",
|
||||||
init: function () {
|
init: function () {
|
||||||
this.on("sending", function (file, xhr, formData) {
|
this.on("sending", function (file, xhr, formData) {
|
||||||
|
@ -1237,9 +1282,11 @@ if (isset($_GET['upload']) && !FM_READONLY) {
|
||||||
});
|
});
|
||||||
}).on("success", function (res) {
|
}).on("success", function (res) {
|
||||||
let _response = JSON.parse(res.xhr.response);
|
let _response = JSON.parse(res.xhr.response);
|
||||||
|
|
||||||
if(_response.status == "error") {
|
if(_response.status == "error") {
|
||||||
toast(_response.info);
|
toast(_response.info);
|
||||||
}
|
}
|
||||||
|
|
||||||
}).on("error", function(file, response) {
|
}).on("error", function(file, response) {
|
||||||
toast(response);
|
toast(response);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue