示例#1
0
function get_total_dir_size($path)
{
    $handle = @opendir($path);
    if ($handle) {
        $files = array();
        $folders = array();
        $size = 0;
        while (($file = readdir($handle)) !== false) {
            if ($file != '.' && $file != '..') {
                if (is_file($path . $file)) {
                    $files[] = $file;
                } else {
                    $folders[] = $file;
                }
            }
        }
        closedir($handle);
        //count size of files in the folder
        foreach ($files as $k => $file) {
            $size += filesize($path . $file);
        }
        //count size of files in subfolders
        foreach ($folders as $k => $file) {
            $size += get_total_dir_size($path . $file . '/');
        }
        return $size;
    }
    return false;
}
示例#2
0
 function draw_dir_tree($files_path, $files_url, $file_type = '', &$id, $level = 1)
 {
     global $initial_files_path;
     global $initial_files_url;
     global $del_path;
     global $text;
     global $lang;
     global $cur_dir_id;
     //    global $last_id;
     //    global $last_path;
     //    global $last_url;
     //prepare list of files and directories
     $entries = array();
     $files = array();
     $indx = 1;
     $abs_files_path = abs_path($files_path);
     $handle = @opendir($abs_files_path);
     if ($handle) {
         while (($file = readdir($handle)) !== false) {
             if ($file != '.' && $file != '..') {
                 if (is_file($abs_files_path . $file)) {
                     //files
                     $files[] = $file;
                 } else {
                     //directory
                     $entries[$indx]['name'] = $file;
                     $entries[$indx]['is_dir'] = true;
                     $indx++;
                 }
             }
         }
         closedir($handle);
     } else {
         echo $text['WrongFilesPath'] . ' "' . $files_path . '"!';
         return;
     }
     usort($entries, "cmp");
     usort($files, "cmp");
     //add list of files to list of directories
     while (list($k, $val) = each($files)) {
         $entries[$indx++]['name'] = $val;
     }
     if ($level > 1 && !($del_path && ereg("^{$files_path}(.*)", $del_path))) {
         $closed = true;
     } else {
         $closed = false;
     }
     if ($level == 1) {
         global $re_set_total_size;
         if ($re_set_total_size) {
             $total_dir_size = get_total_dir_size(abs_path(stripslashes($files_path)));
             echo '<tr><td class="re_remote_dirsize">' . $text['FreeSpace'] . ':&nbsp;' . convert_file_size($re_set_total_size - $total_dir_size) . '/' . convert_file_size($re_set_total_size) . '</td></tr>';
         }
         echo '<tr>';
         echo '<td>';
         echo '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>';
         echo '<b><a class="re_remote" id="dir_a' . $id . '" href="javascript: set_cur_dir(' . $id . ',\'' . $initial_files_path . '\',\'' . $initial_files_url . '\');" style="color:red">' . $text['root'] . '</a></b>';
         // style="color:red"
         echo '</td>';
         echo '<td align="right">';
         global $re_set_can_create_dir;
         if ($re_set_can_create_dir) {
             echo '<a class="re_remote" href="#" onclick="window.remote_files_form.submit(); return false;">' . $text['CreateFolder'] . '</a>';
         } else {
             echo '&nbsp';
         }
         echo '</td>';
         echo '</tr>';
         echo '</table>';
         echo '</td>';
         echo '</tr>';
     }
     echo '<tr height=0><td height=0><div id="dir_div' . $id . '"';
     //if just created/renamed or deleted file/dir, make all parent dirs visible
     if ($closed) {
         echo 'style="display:none;"';
     }
     echo '>';
     echo '<table border="0" cellspacing="0" cellpadding="0" width="100%" height="100%">';
     //adjust row heights
     echo '<tr><td>';
     echo '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>';
     echo '</td></tr></table>';
     echo '</td></tr>';
     //draw content of the current directory
     if ($entries) {
         global $re_set_can_rename_file;
         global $re_set_can_delete_file;
         global $re_set_can_rename_dir;
         global $re_set_can_delete_dir;
         while (list($k, $val) = each($entries)) {
             $file = $val['name'];
             if (!isset($val['is_dir']) || !$val['is_dir']) {
                 //files
                 switch ($file_type) {
                     case "image":
                     case "flash":
                         $size = @getimagesize($abs_files_path . $file);
                         if ($size[2] != 4 && $size[2] != 13 && $file_type == 'image' && $size[2] || ($size[2] == 4 || $size[2] == 13) && $file_type == 'flash') {
                             //image&flash
                             echo "<tr onmouseover=\"bgColor='#6699CC';\" onmouseout=\"bgColor='';\"><td width=\"100%\">\n";
                             echo '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>';
                             echo indent($level);
                             echo '<a class="re_remote" href="#" onClick="select_remote_file(\'' . correct_path($files_url . $file) . '\',' . $size[0] . ',' . $size[1] . '); return false;">' . $file . '</a>&nbsp;';
                             echo "</td>";
                             echo '<td width="1">';
                             if ($re_set_can_rename_file) {
                                 echo '<a class="re_remote" href="?files_path=' . $initial_files_path . '&files_url=' . $initial_files_url . '&file_type=' . $file_type . '&action=rename&del_path=' . $files_path . '&file=' . rawurlencode($file) . '&lang=' . $lang . (isset($_SESSION) ? '&' . SID : '') . '">r</a>';
                             }
                             echo '&nbsp;</td>';
                             echo '<td width="1">';
                             if ($re_set_can_delete_file) {
                                 echo '<a class="re_remote" href="?files_path=' . $initial_files_path . '&files_url=' . $initial_files_url . '&file_type=' . $file_type . '&action=delete&del_path=' . $files_path . '&file=' . rawurlencode($file) . '&lang=' . $lang . (isset($_SESSION) ? '&' . SID : '') . '" onclick="javascript: if (window.confirm(\'' . $text['Delete'] . ' \\\'' . str_replace('\'', '\\\'', $file) . '\\\'?\')) return true; else return false;">x</a>';
                             }
                             echo '</td>';
                             //                echo '<td width="1"><a class="re_remote" href="javascript: window.location = \'?files_path='.$initial_files_path.'&files_url='.$initial_files_url.'&file_type='.$file_type.'&action=rename&del_path='.$files_path.'&file='.$file.'&lang='.$lang.'\';">r</a>&nbsp;</td>';
                             //                echo '<td width="1"><a class="re_remote" href="javascript: if (window.confirm(\'Delete \\\''.$file.'\\\'?\')) window.location = \'?files_path='.$initial_files_path.'&files_url='.$initial_files_url.'&file_type='.$file_type.'&action=delete&del_path='.$files_path.'&file='.$file.'&lang='.$lang.'\';">x</a></td>';
                             echo '</tr></table></td>';
                             echo "</tr>\n";
                             //adjust row heights
                             echo '<tr><td>';
                             echo '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>';
                             echo '</td></tr></table>';
                             echo '</td></tr>';
                         }
                         break;
                     default:
                         echo "<tr onmouseover=\"bgColor='#6699CC';\" onmouseout=\"bgColor='';\"><td width=\"100%\">\n";
                         echo '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>';
                         echo indent($level);
                         echo '<a class="re_remote" href="#" onClick="select_remote_file(\'' . correct_path($files_url . $file) . '\'); return false;">' . $file . '</a>&nbsp;';
                         echo "</td>";
                         echo '<td width="1">';
                         if ($re_set_can_rename_file) {
                             echo '<a class="re_remote" href="?files_path=' . $initial_files_path . '&files_url=' . $initial_files_url . '&file_type=' . $file_type . '&action=rename&del_path=' . $files_path . '&file=' . rawurlencode($file) . '&lang=' . $lang . (isset($_SESSION) ? '&' . SID : '') . '">r</a>';
                         }
                         echo '&nbsp;</td>';
                         echo '<td width="1">';
                         if ($re_set_can_delete_file) {
                             echo '<a class="re_remote" href="?files_path=' . $initial_files_path . '&files_url=' . $initial_files_url . '&file_type=' . $file_type . '&action=delete&del_path=' . $files_path . '&file=' . rawurlencode($file) . '&lang=' . $lang . (isset($_SESSION) ? '&' . SID : '') . '" onclick="javascript: if (window.confirm(\'' . $text['Delete'] . ' \\\'' . str_replace('\'', '\\\'', $file) . '\\\'?\')) return true; else return false;">x</a>';
                         }
                         echo '</td>';
                         //              echo '<td width="1"><a class="re_remote" href="javascript: window.location = \'?files_path='.$initial_files_path.'&files_url='.$initial_files_url.'&file_type='.$file_type.'&action=rename&del_path='.$files_path.'&file='.rawurlencode($file).'&lang='.$lang.'\';">r</a>&nbsp;</td>';
                         //              echo '<td width="1"><a class="re_remote" href="javascript: if (window.confirm(\'Delete \\\''.$file.'\\\'?\')) window.location = \'?files_path='.$initial_files_path.'&files_url='.$initial_files_url.'&file_type='.$file_type.'&action=delete&del_path='.$files_path.'&file='.$file.'&lang='.$lang.'\';">x</a></td>';
                         echo '</tr></table></td>';
                         echo "</tr>\n";
                         //adjust row heights
                         echo '<tr><td>';
                         echo '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>';
                         echo '</td></tr></table>';
                         echo '</td></tr>';
                         break;
                 }
                 //switch
             } else {
                 //directories
                 $id++;
                 //get unique div id
                 if (!($del_path && ereg("^{$files_path}{$file}/(.*)", $del_path))) {
                     $closed = true;
                 } else {
                     $closed = false;
                     if ($del_path == $files_path . $file . '/') {
                         $cur_dir_id = $id;
                     }
                 }
                 echo "<tr onmouseover=\"bgColor='#6699CC';\" onmouseout=\"bgColor='';\"><td width=\"100%\">\n";
                 echo '<table border="0" cellspacing="0" cellpadding="0" width="100%"><tr><td>';
                 echo indent($level);
                 echo '<img width="11" height="11" id="dir_img' . $id . '" style="cursor:hand" onclick="switch_div(' . $id . ');" src="images/';
                 if (!$closed) {
                     echo 'minus.gif';
                 } else {
                     echo 'plus.gif';
                 }
                 echo '">&nbsp;';
                 echo '<b><a class="re_remote" id="dir_a' . $id . '" href="javascript: set_cur_dir(' . $id . ',\'' . str_replace('\'', '\\\'', $files_path . $file) . '/\',\'' . str_replace('\'', '\\\'', $files_url . $file) . '/\');">' . $file . '</a></b>&nbsp;</td>';
                 echo '<td width="1">';
                 if ($re_set_can_rename_dir) {
                     echo '<a class="re_remote" href="?files_path=' . $initial_files_path . '&files_url=' . $initial_files_url . '&file_type=' . $file_type . '&action=rename&del_path=' . $files_path . '&file=' . rawurlencode($file) . '&lang=' . $lang . (isset($_SESSION) ? '&' . SID : '') . '">r</a>';
                 }
                 echo '&nbsp;</td>';
                 echo '<td width="1">';
                 if ($re_set_can_delete_dir) {
                     echo '<a class="re_remote" href="?files_path=' . $initial_files_path . '&files_url=' . $initial_files_url . '&file_type=' . $file_type . '&action=delete&del_path=' . $files_path . '&file=' . rawurlencode($file) . '&lang=' . $lang . (isset($_SESSION) ? '&' . SID : '') . '" onclick="javascript: if (window.confirm(\'' . $text['Delete'] . ' \\\'' . str_replace('\'', '\\\'', $file) . '\\\'?\')) return true; else return false;">x</a>';
                 }
                 echo '</td>';
                 //          echo '<td width="1"><a class="re_remote" href="javascript: window.location = \'?files_path='.$initial_files_path.'&files_url='.$initial_files_url.'&file_type='.$file_type.'&action=rename&del_path='.$files_path.'&file='.rawurlencode($file).'&lang='.$lang.'\';">r</a>&nbsp;</td>';
                 //          echo '<td width="1"><a class="re_remote" href="javascript: if (window.confirm(\'Delete \\\''.$file.'\\\'?\')) window.location = \'?files_path='.$initial_files_path.'&files_url='.$initial_files_url.'&file_type='.$file_type.'&action=delete&del_path='.$files_path.'&file='.rawurlencode($file).'&lang='.$lang.'\';">x</a></td>';
                 echo '</tr></table></td>';
                 echo "</tr>\n";
                 draw_dir_tree($files_path . $file . '/', $files_url . $file . '/', $file_type, $id, $level + 1);
             }
         }
     }
     echo '</table></div></td></tr>';
 }
示例#3
0
     }
 }
 if ($avail) {
     $local_file = $_FILES['local_file']['tmp_name'];
     if (!$local_file) {
         $local_file = $HTTP_POST_FILES['local_file']['tmp_name'];
     }
     $local_file = str_replace("\\\\", "\\", $local_file);
     //    if(file_exists($local_file)){
     $new_file_size = filesize($local_file);
     //check if size of the file do not exceed max limit
     if ($re_set_max_size < 0 || $new_file_size <= $re_set_max_size) {
         //calculate total size if necessary as it could be slow if
         //number of files and folder is very big
         if ($re_set_total_size > 0) {
             $total_dir_size = get_total_dir_size(abs_path(stripslashes($initial_files_path)));
         } else {
             $total_dir_size = false;
         }
         if ($re_set_total_size == 0 || $total_dir_size === false || $new_file_size + $total_dir_size <= $re_set_total_size) {
             $name = $_FILES['local_file']['name'];
             if (!$name) {
                 $name = $HTTP_POST_FILES['local_file']['name'];
             }
             $upload_file = abs_path(stripslashes($files_path . $name));
             //check if can override existing file if necessary
             if (!file_exists($upload_file) || $re_set_allow_override) {
                 $size = @getimagesize($local_file);
                 $lower_file_ext = strtolower(file_ext($name));
                 if ((!$re_set_avail_files || in_array($lower_file_ext, $re_set_avail_files)) && (!$re_set_not_avail_files || !in_array($lower_file_ext, $re_set_not_avail_files))) {
                     $avail_ext = true;