mirror of
https://github.com/myvesta/vesta
synced 2025-08-19 13:01:52 -07:00
File Manger stuff
This commit is contained in:
parent
e3f636cb3a
commit
13d3fd476b
1 changed files with 67 additions and 40 deletions
|
@ -4,18 +4,25 @@
|
||||||
//define(LISTING_TIMEOUT, 0.000001);
|
//define(LISTING_TIMEOUT, 0.000001);
|
||||||
define(LISTING_TIMEOUT, 5);
|
define(LISTING_TIMEOUT, 5);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//echo 'files: ';
|
//echo 'files: ';
|
||||||
//$files = scandir(__DIR__);
|
//$files = scandir(__DIR__);
|
||||||
|
|
||||||
|
|
||||||
//echo '<pre>';
|
//echo '<pre>';
|
||||||
//print_r($files);
|
//print_r($files);
|
||||||
|
|
||||||
|
|
||||||
//$_REQUEST['sort_field'] = 'size';
|
//$_REQUEST['sort_field'] = 'size';
|
||||||
$_REQUEST['sort_field'] = 'name';
|
$_REQUEST['sort_field'] = 'name';
|
||||||
//$_REQUEST['sort_field'] = 'atime';
|
//$_REQUEST['sort_field'] = 'atime';
|
||||||
//$_REQUEST['sort_field'] = 'mtime';
|
//$_REQUEST['sort_field'] = 'mtime';
|
||||||
$_REQUEST['sort_desc'] = 1;
|
$_REQUEST['sort_desc'] = 1;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
+- copy file / dir [ recursive ]
|
+- copy file / dir [ recursive ]
|
||||||
+- rename(move) file / dir
|
+- rename(move) file / dir
|
||||||
|
@ -26,7 +33,7 @@ $_REQUEST['sort_desc'] = 1;
|
||||||
+- create dir
|
+- create dir
|
||||||
*/
|
*/
|
||||||
|
|
||||||
switch($_REQUEST['action']) {
|
switch($_REQUEST['action']){
|
||||||
case 'copy': fm_copy($_REQUEST['source'], $_REQUEST['dest']); break;
|
case 'copy': fm_copy($_REQUEST['source'], $_REQUEST['dest']); break;
|
||||||
case 'rename': fm_rename($_REQUEST['source'], $_REQUEST['dest']); break;
|
case 'rename': fm_rename($_REQUEST['source'], $_REQUEST['dest']); break;
|
||||||
case 'delete': fm_delete($_REQUEST['source']); break;
|
case 'delete': fm_delete($_REQUEST['source']); break;
|
||||||
|
@ -46,12 +53,24 @@ switch($_REQUEST['action']) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//echo $_GET['sort_field'];
|
//echo $_GET['sort_field'];
|
||||||
|
|
||||||
// if(in_array($_GET['sort_field'], $available_sort_fields)){
|
// if(in_array($_GET['sort_field'], $available_sort_fields)){
|
||||||
// echo '1';
|
// echo '1';
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
upload_file
|
upload_file
|
||||||
|
|
||||||
|
@ -68,16 +87,17 @@ switch($_REQUEST['action']) {
|
||||||
download file / image
|
download file / image
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function fm_create_file($filename)
|
|
||||||
{
|
|
||||||
|
function fm_create_file($filename){
|
||||||
if(is_file($filename))
|
if(is_file($filename))
|
||||||
return array('error' => 'file exists', 'code' => 1);
|
return array('error' => 'file exists', 'code' => 1);
|
||||||
|
|
||||||
return (bool) fopen($filename, 'w'); // (bool) > !!, sorry
|
return !!fopen($filename, 'w');
|
||||||
}
|
}
|
||||||
|
|
||||||
function fm_create_dir($dirname)
|
|
||||||
{
|
function fm_create_dir($dirname){
|
||||||
if(is_dir($filename))
|
if(is_dir($filename))
|
||||||
return array('error' => 'directory exists', 'code' => 1);
|
return array('error' => 'directory exists', 'code' => 1);
|
||||||
|
|
||||||
|
@ -85,49 +105,49 @@ function fm_create_dir($dirname)
|
||||||
return mkdir($dirname);
|
return mkdir($dirname);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fm_chown($filename, $recursive = 0, $uid = FALSE, $gid = FALSE)
|
|
||||||
{
|
function fm_chown($filename, $recursive = 0, $uid = FALSE, $gid = FALSE){
|
||||||
if (is_dir($filename) && $recursive) {
|
if(is_dir($filename) && $recursive){
|
||||||
$dir_handle = opendir($dir);
|
$dir_handle = opendir($dir);
|
||||||
while ($item = readdir($dir_handle)) {
|
while ($item = readdir($dir_handle)){
|
||||||
if (!in_array($item, array('.','..'))) {
|
if (!in_array($item, array('.','..'))){
|
||||||
$new_item = $filename.'/'.$item;
|
$new_item = $filename.'/'.$item;
|
||||||
|
|
||||||
if ($uid !== FALSE) chown($new_item, (int)$uid);
|
if($uid !== FALSE) chown($new_item, (int)$uid);
|
||||||
if ($gid !== FALSE) chgrp($new_item, (int)$gid);
|
if($gid !== FALSE) chgrp($new_item, (int)$gid);
|
||||||
|
|
||||||
if (is_dir($new_item)) {
|
if(is_dir($new_item)){
|
||||||
fm_chown($new_item, $recursive, $uid, $gid);
|
fm_chown($new_item, $recursive, $uid, $gid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}else{
|
||||||
if($uid !== FALSE) chown($filename, (int)$uid);
|
if($uid !== FALSE) chown($filename, (int)$uid);
|
||||||
if($gid !== FALSE) chgrp($filename, (int)$gid);
|
if($gid !== FALSE) chgrp($filename, (int)$gid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fm_chmod($filename, $recursive = 0, $mode)
|
|
||||||
{
|
function fm_chmod($filename, $recursive = 0, $mode){
|
||||||
if(is_dir($filename) && $recursive) {
|
if(is_dir($filename) && $recursive){
|
||||||
$dir_handle = opendir($dir);
|
$dir_handle = opendir($dir);
|
||||||
while ($item = readdir($dir_handle)) {
|
while ($item = readdir($dir_handle)){
|
||||||
if (!in_array($item, array('.','..'))) {
|
if (!in_array($item, array('.','..'))){
|
||||||
$new_item = $filename.'/'.$item;
|
$new_item = $filename.'/'.$item;
|
||||||
chmod($new_item, octdec($mode));
|
chmod($new_item, octdec($mode));
|
||||||
|
|
||||||
if (is_dir($new_item)) {
|
if(is_dir($new_item)){
|
||||||
fm_chmod($new_item, $recursive, $mode);
|
fm_chmod($new_item, $recursive, $mode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}else{
|
||||||
chmod($filename, octdec($mode));
|
chmod($filename, octdec($mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fm_delete($filename)
|
|
||||||
{
|
function fm_delete($filename){
|
||||||
if(is_dir($filename)){
|
if(is_dir($filename)){
|
||||||
foreach (
|
foreach (
|
||||||
$iterator = new RecursiveIteratorIterator(
|
$iterator = new RecursiveIteratorIterator(
|
||||||
|
@ -142,21 +162,19 @@ function fm_delete($filename)
|
||||||
// copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
|
// copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}else{
|
||||||
return unlink($filename);
|
return unlink($filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function fm_rename($source, $dest)
|
function fm_rename($source, $dest){
|
||||||
{
|
|
||||||
return rename($source, $dest);
|
return rename($source, $dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function fm_copy($source, $dest)
|
function fm_copy($source, $dest){
|
||||||
{
|
if(is_dir($source)){
|
||||||
if (is_dir($source)) {
|
|
||||||
foreach (
|
foreach (
|
||||||
$iterator = new RecursiveIteratorIterator(
|
$iterator = new RecursiveIteratorIterator(
|
||||||
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
|
new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS),
|
||||||
|
@ -169,13 +187,14 @@ function fm_copy($source, $dest)
|
||||||
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
|
copy($item, $dest . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
return copy($source, $dest);
|
return copy($source, $dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function list_dir()
|
|
||||||
{
|
function list_dir(){
|
||||||
$dir_iterator = new RecursiveDirectoryIterator("/path");
|
$dir_iterator = new RecursiveDirectoryIterator("/path");
|
||||||
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
|
$iterator = new RecursiveIteratorIterator($dir_iterator, RecursiveIteratorIterator::SELF_FIRST);
|
||||||
// could use CHILD_FIRST if you so wish
|
// could use CHILD_FIRST if you so wish
|
||||||
|
@ -195,9 +214,12 @@ function list_dir()
|
||||||
echo "\nTotal file size: ", $size, " bytes\n";
|
echo "\nTotal file size: ", $size, " bytes\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// fast removing directory
|
/// fast removing directory
|
||||||
function rmrf($dir)
|
function rmrf($dir) {
|
||||||
{
|
|
||||||
foreach (glob($dir) as $file) {
|
foreach (glob($dir) as $file) {
|
||||||
if (is_dir($file)) {
|
if (is_dir($file)) {
|
||||||
rmrf("$file/*");
|
rmrf("$file/*");
|
||||||
|
@ -208,6 +230,9 @@ function rmrf($dir)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function dir_list($dir, $sort = 0)
|
function dir_list($dir, $sort = 0)
|
||||||
{
|
{
|
||||||
$sort_order_for_filename = SORT_ASC;
|
$sort_order_for_filename = SORT_ASC;
|
||||||
|
@ -227,7 +252,7 @@ function dir_list($dir, $sort = 0)
|
||||||
if (!in_array($object, array('.','..'))){
|
if (!in_array($object, array('.','..'))){
|
||||||
$filename = $dir . $object;
|
$filename = $dir . $object;
|
||||||
$time = microtime(true) - $start;
|
$time = microtime(true) - $start;
|
||||||
if ($time <= LISTING_TIMEOUT) {
|
if($time <= LISTING_TIMEOUT){
|
||||||
$stats = stat($filename);
|
$stats = stat($filename);
|
||||||
$mode = explain_mode($stats['mode']);
|
$mode = explain_mode($stats['mode']);
|
||||||
$perms = decoct(fileperms($filename));
|
$perms = decoct(fileperms($filename));
|
||||||
|
@ -249,11 +274,8 @@ function dir_list($dir, $sort = 0)
|
||||||
);
|
);
|
||||||
}else{
|
}else{
|
||||||
$listing['timeout_exeeded'] = TRUE;
|
$listing['timeout_exeeded'] = TRUE;
|
||||||
if (is_dir($filename)) {
|
if(is_dir($filename)){ $type = 'd';
|
||||||
$type = 'd';
|
}else{ $type = '-'; }
|
||||||
} else {
|
|
||||||
$type = '-';
|
|
||||||
}
|
|
||||||
|
|
||||||
$item = array(
|
$item = array(
|
||||||
'name' => $object,
|
'name' => $object,
|
||||||
|
@ -272,6 +294,7 @@ function dir_list($dir, $sort = 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$listing['count']++;
|
$listing['count']++;
|
||||||
|
|
||||||
if($item['type'] == 'd'){
|
if($item['type'] == 'd'){
|
||||||
|
@ -288,6 +311,7 @@ function dir_list($dir, $sort = 0)
|
||||||
}
|
}
|
||||||
$listing['time'] = microtime(TRUE) - $start;
|
$listing['time'] = microtime(TRUE) - $start;
|
||||||
|
|
||||||
|
|
||||||
if(!$listing['timeout_exeeded']){
|
if(!$listing['timeout_exeeded']){
|
||||||
if(in_array($_REQUEST['sort_field'], $available_sort_fields)){
|
if(in_array($_REQUEST['sort_field'], $available_sort_fields)){
|
||||||
if($_REQUEST['sort_desc']){
|
if($_REQUEST['sort_desc']){
|
||||||
|
@ -300,6 +324,7 @@ function dir_list($dir, $sort = 0)
|
||||||
|
|
||||||
return $listing;
|
return $listing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function explain_mode($mode)
|
function explain_mode($mode)
|
||||||
{
|
{
|
||||||
|
@ -330,3 +355,5 @@ function explain_mode($mode)
|
||||||
|
|
||||||
return $info;
|
return $info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue