in-tree extjs-upload-widget

This commit is contained in:
gitadmin committed 2018-08-15 11:12:01 +03:00
1 parent 025b5f745e
commit 4635ee3492
46 files changed
+3166

No files matched your search

@@ -0,0 +1,23 @@
<?php
function _log($value)
{
error_log(print_r($value, true));
}
function _response($success = true, $message = 'OK')
{
$response = array(
'success' => $success,
'message' => $message
);
echo json_encode($response);
exit();
}
function _error($message)
{
return _response(false, $message);
}
@@ -0,0 +1,5 @@
<?php
return array(
'upload_dir' => '/tmp/test-upload-dir',
'fake' => false
);
+138
View File
@@ -0,0 +1,138 @@
Ext.Loader.setPath({
'Ext.ux' : 'external'
});
Ext.application({
requires : [
'Ext.ux.upload.Dialog'
],
name : 'Example',
appFolder : 'app',
launch : function() {
debug = console;
Ext.create('Ext.container.Viewport', {
layout : 'fit'
});
var appPanel = Ext.create('Ext.window.Window', {
title : 'Files',
width : 600,
height : 400,
closable : false,
modal : true,
bodyPadding : 5,
uploadComplete : function(items) {
var output = 'Uploaded files: <br>';
Ext.Array.each(items, function(item) {
output += item.getFilename() + ' (' + item.getType() + ', '
+ Ext.util.Format.fileSize(item.getSize()) + ')' + '<br>';
});
this.update(output);
}
});
appPanel.syncCheckbox = Ext.create('Ext.form.field.Checkbox', {
inputValue : true,
checked : true
});
appPanel.addDocked({
xtype : 'toolbar',
dock : 'top',
items : [
{
xtype : 'button',
text : 'Raw PUT/POST Upload',
scope : appPanel,
handler : function() {
var uploadPanel = Ext.create('Ext.ux.upload.Panel', {
uploaderOptions : {
url : 'upload.php'
},
filenameEncoder : 'Ext.ux.upload.header.Base64FilenameEncoder',
synchronous : appPanel.syncCheckbox.getValue()
});
var uploadDialog = Ext.create('Ext.ux.upload.Dialog', {
dialogTitle : 'My Upload Dialog',
panel : uploadPanel
});
this.mon(uploadDialog, 'uploadcomplete', function(uploadPanel, manager, items, errorCount) {
this.uploadComplete(items);
if (!errorCount) {
uploadDialog.close();
}
}, this);
uploadDialog.show();
}
}, '-', {
xtype : 'button',
text : 'Multipart Upload',
scope : appPanel,
handler : function() {
var uploadPanel = Ext.create('Ext.ux.upload.Panel', {
uploader : 'Ext.ux.upload.uploader.FormDataUploader',
uploaderOptions : {
url : 'upload_multipart.php'
},
synchronous : appPanel.syncCheckbox.getValue()
});
var uploadDialog = Ext.create('Ext.ux.upload.Dialog', {
dialogTitle : 'My Upload Dialog',
panel : uploadPanel
});
this.mon(uploadDialog, 'uploadcomplete', function(uploadPanel, manager, items, errorCount) {
this.uploadComplete(items);
if (!errorCount) {
uploadDialog.close();
}
}, this);
uploadDialog.show();
}
}, '-', {
xtype : 'button',
text : 'Dummy upload',
scope : appPanel,
handler : function() {
var uploadPanel = Ext.create('Ext.ux.upload.Panel', {
uploader : 'Ext.ux.upload.uploader.DummyUploader',
synchronous : appPanel.syncCheckbox.getValue()
});
var uploadDialog = Ext.create('Ext.ux.upload.Dialog', {
dialogTitle : 'My Upload Dialog',
panel : uploadPanel
});
this.mon(uploadDialog, 'uploadcomplete', function(uploadPanel, manager, items, errorCount) {
this.uploadComplete(items);
if (!errorCount) {
uploadDialog.close();
}
}, this);
uploadDialog.show();
}
}, '->', appPanel.syncCheckbox, 'Synchronous upload'
]
})
appPanel.show();
}
});
+1
View File
@@ -0,0 +1 @@
../docs
+1
View File
@@ -0,0 +1 @@
../../lib/upload
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

@@ -0,0 +1,14 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File upload</title>
<link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
<link rel="stylesheet" type="text/css" href="external/upload/css/upload.css">
<script type="text/javascript" src="extjs/ext-debug.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body>
</body>
</html>
+16
View File
@@ -0,0 +1,16 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File upload</title>
<!-- <link rel="stylesheet" type="text/css" href="extjs/resources/css/ext-all.css">
-->
<link rel="stylesheet" type="text/css" href="extjs/packages/ext-theme-classic/build/resources/ext-theme-classic-all.css">
<link rel="stylesheet" type="text/css" href="external/upload/css/upload.css">
<script type="text/javascript" src="extjs/build/ext-debug.js"></script>
<script type="text/javascript" src="app.js"></script>
</head>
<body>
</body>
</html>
@@ -0,0 +1,74 @@
<?php
/**
* Example processing of raw PUT/POST uploaded files.
* File metadata may be sent through appropriate HTTP headers:
* - file name - the 'X-File-Name' proprietary header
* - file size - the standard 'Content-Length' header or the 'X-File-Size' proprietary header
* - file type - the standard 'Content-Type' header or the 'X-File-Type' proprietary header
*
* Raw data are read from the standard input.
* The response should be a JSON encoded string with these items:
* - success (boolean) - if the upload has been successful
* - message (string) - optional message, useful in case of error
*/
require __DIR__ . '/_common.php';
$config = require __DIR__ . '/_config.php';
/*
* You should check these values for XSS or SQL injection.
*/
if (!isset($_SERVER['HTTP_X_FILE_NAME'])) {
_error('Unknown file name');
}
$fileName = $_SERVER['HTTP_X_FILE_NAME'];
if (isset($_SERVER['HTTP_X_FILENAME_ENCODER']) && 'base64' == $_SERVER['HTTP_X_FILENAME_ENCODER']) {
$fileName = base64_decode($fileName);
}
$fileName = htmlspecialchars($fileName);
$mimeType = htmlspecialchars($_SERVER['HTTP_X_FILE_TYPE']);
$size = intval($_SERVER['HTTP_X_FILE_SIZE']);
$inputStream = fopen('php://input', 'r');
$outputFilename = $config['upload_dir'] . '/' . $fileName;
$realSize = 0;
$data = '';
if ($inputStream) {
if (! $config['fake']) {
$outputStream = fopen($outputFilename, 'w');
if (! $outputStream) {
_error('Error creating local file');
}
}
while (! feof($inputStream)) {
$bytesWritten = 0;
$data = fread($inputStream, 1024);
if (! $config['fake']) {
$bytesWritten = fwrite($outputStream, $data);
} else {
$bytesWritten = strlen($data);
}
if (false === $bytesWritten) {
_error('Error writing data to file');
}
$realSize += $bytesWritten;
}
if (! $config['fake']) {
fclose($outputStream);
}
} else {
_error('Error reading input');
}
if ($realSize != $size) {
_error('The actual size differs from the declared size in the headers');
}
_log(sprintf("[raw] Uploaded %s, %s, %d byte(s)", $fileName, $mimeType, $realSize));
_response();
@@ -0,0 +1,39 @@
<?php
/*
* Simple example backend script to serve the FormDataUploader (multipart upload).
*/
require __DIR__ . '/_common.php';
$config = require __DIR__ . '/_config.php';
$fileName = '';
$mimeType = '';
$fileSize = 0;
/*
* If there is no file data, something wrong has happened. One possible reason is - the uploaded
* file size exceeds the maximum allowed POST or upload size.
*/
if (empty($_FILES)) {
_error('No file received');
}
foreach ($_FILES as $fileName => $fileData) {
if ($fileData['error'] !== 0) {
_error(sprintf("Upload error '%d'", $fileData['error']));
}
$fileName = htmlspecialchars($fileData['name']);
$mimeType = $fileData['type'];
$fileSize = $fileData['size'];
$targetFile = $config['upload_dir'] . '/' . $fileName;
if (! $config['fake']) {
if (! move_uploaded_file($fileData['tmp_name'], $targetFile)) {
_error('Error saving uploaded file');
}
}
}
_log(sprintf("[multipart] Uploaded %s, %s, %d byte(s)", $fileName, $mimeType, $fileSize));
_response();