PDA

View Full Version : ext.ux.HtmlEditor.FileManager



farcek
24 Feb 2010, 2:49 AM
ExtJs - HtmlEditor - plugn FileManager (Ext.ux.HtmlEditor.FileManager) version 0.1

Blog : http://farcek.blogspot.com/2010/02/extjs-htmleditor-plugn-filemanager-ext.html



fileManage.
file upload.

http://2.bp.blogspot.com/_3JyZhFVv8UA/S345TnGPakI/AAAAAAAAAAc/XcgruuDFrpk/s320/11.jpg
http://1.bp.blogspot.com/_3JyZhFVv8UA/S345bjZ-7mI/AAAAAAAAAAk/L5gb9kYJCyI/s320/22.jpg

Header (includes)


<script type="text/javascript" src="Ext/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="Ext/ext-all-debug.js"></script>
<link type="text/css" rel="stylesheet" href="Ext/resources/css/reset-min.css" />
<link type="text/css" rel="stylesheet" href="Ext/resources/css/ext-all.css" />

<script type="text/javascript" src="Ext/ux/FileUploadField.js"></script>
<link type="text/css" rel="stylesheet" href="Ext/ux/file-upload.css" >
<script type="text/javascript" src="Ext/ux/HtmlEditor/FileManager/FileManager.js"></script>
<link type="text/css" rel="stylesheet" href="Ext/ux/HtmlEditor/FileManager/css/style.css" >


Useing


new Ext.form.HtmlEditor({
renderTo: Ext.getBody(),
width: 900,
height: 300,
plugins: [new Ext.ux.HtmlEditor.FileManager({
url : 'fileActions.php'
})]
});


fileActions.php

This is script not block hacking. You must use SESSION for your security.



$url = "/userfiles/images/";
$dir = getcwd () . $url;
$allowImageExtension = array ('jpg', 'gif', 'png' );
$allowObjectExtension = array ('swf' );
$allowDataExtension = array ('zip','rar','xml','exe','mp3','pdf','doc','docx' );

$action = trim ( @$_REQUEST ['faction'] );
function getFileType($name) {
global $allowImageExtension, $allowObjectExtension, $allowDataExtension;
$ar = explode ( ".", $name );
if (count ( $ar ) > 1) {
$extension = array_pop ( $ar );
if (in_array ( $extension, $allowImageExtension ))
return 'image';
if (in_array ( $extension, $allowObjectExtension ))
return 'object';
if (in_array ( $extension, $allowDataExtension ))
return 'data';
}
return null;
}

function filelist() {
global $dir, $url;

$files = array ();
$d = dir ( $dir );
while ( true ) {
$name = $d->read ();
if ($name == false) {
break;
}
if ($name == "." || $name == "..")
continue;
if (filetype ( $dir . $name ) == "dir")
continue;
$type = getFileType ( $name );
if ($type === null)
continue;

$size = filesize ( $dir . $name );
$lastmod = date ( "Y/m/d H:i", filemtime ( $dir . $name ) );
list ( $w, $h, $fileType, $attr ) = @getimagesize ( $dir . $name );

$files [] = array ('name' => $name, 'type' => $type, 'size' => $size, 'lastmod' => $lastmod, 'url' => $url . $name, 'w' => intval ( $w ), 'h' => intval ( $h ) );
}
$d->close ();
$o = array ('files' => $files );
echo json_encode ( $o );
}
function upload() {
global $dir;
$res = array ("success" => false );
if (isset ( $_FILES ['files'] )) {
$files = $_FILES ['files'];
if (is_array ( $files ['name'] )) {
$eFiles = array ();
$sFiles = array ();
foreach ( $files ['name'] as $k => $it ) {
$name = $files ['name'] [$k];
$type = $files ['type'] [$k];
$tname = $files ['tmp_name'] [$k];
$error = $files ['error'] [$k];
$size = $files ['size'] [$k];

if (getFileType ( $name ) !== null && $error == 0 && $size > 0) {
move_uploaded_file ( $tname, $dir . $name ) ? $sFiles [] = $name : $eFiles [] = $name;
} else {
$eFiles [] = $name;
}
}

if (count ( $eFiles ) == 0 && count ( $sFiles ) > 0) {
$error = false;
} else {
$error = true;
}
$res ['success'] = ! $error;
$res ['msg'] = $error ? 'can not upload. ' . implode ( ', ', $eFiles ) : '...';
echo json_encode ( $res );
return;
}
}

$res ['msg'] = 'not found atache files';
echo json_encode ( $res );
}
function delete() {
global $dir;
$file = $_REQUEST ['file'];
$b = getFileType($file) !== null;
if ($b && unlink ( $dir . $file ) === true) {
echo "{success:true}";
} else {
echo "{success:false}";
}
}
is_callable ( $action ) ? call_user_func ( $action ) : '';

wemerson.januario
24 Feb 2010, 8:22 AM
nice

dawesi
1 Mar 2010, 4:08 PM
nice implimentation

if you're using 3.x you might want to use the SWF upload tool... with flash 10 it's quite a nice little unit, even behind firewalls ;-)

farcek
1 Mar 2010, 9:47 PM
in good time. first local working for finish.

nice implimentation

if you're using 3.x you might want to use the SWF upload tool... with flash 10 it's quite a nice little unit, even behind firewalls ;-)

amt779
18 Apr 2010, 12:24 PM
Hello your plugin is awesomt,
but there serious bug i found in ext.ux.HtmlEditor.FileManager (http://www.extjs.com/forum/showthread.php?92827-ext.ux.HtmlEditor.FileManager).

When i place HtmlEditor (http://www.extjs.com/forum/showthread.php?92827-ext.ux.HtmlEditor.FileManager) on a tab-panel-bar and HtmlEditor (http://www.extjs.com/forum/showthread.php?92827-ext.ux.HtmlEditor.FileManager) includes your plugin (http://www.extjs.com/forum/showthread.php?92827-ext.ux.HtmlEditor.FileManager) ext.ux.HtmlEditor.FileManager (http://www.extjs.com/forum/showthread.php?92827-ext.ux.HtmlEditor.FileManager). Every tab intialased with closable:true;

So when user try to close the tab, all the elements on the tab are being destroyed but ext.ux.HtmlEditor.FileManager (http://www.extjs.com/forum/showthread.php?92827-ext.ux.HtmlEditor.FileManager) is not. And for that reason tab is impossible to close. BugZilla throws couple errors and nothing happens.

I would very appreciate if you'd fix this bug for the next version