Example #1
0
 public function testFilesizeFormat()
 {
     $this->assertEquals('1KB', filesize_format(1024));
     $this->assertEquals('1MB', filesize_format(1024 * 1024));
     $this->assertEquals('1GB', filesize_format(1024 * 1024 * 1024));
     $this->assertEquals('1TB', filesize_format(1024 * 1024 * 1024 * 1024));
 }
Example #2
0
    }
}
# form treatment
# step 1 : we upload the data from the .csv team
if (isset($_POST['step']) and $_POST['step'] == "upload" and $right_user['import_match']) {
    # we check submitted data
    if (!isset($_FILES['file']['name']) or empty($_FILES['file']['name'])) {
        $page['erreur'][$nb_error]['message'] = $lang['match']['E_empty_file'];
        $nb_error++;
    } elseif (!in_array($_FILES['file']['type'], $type_mime_allowed)) {
        $var['type'] = implode(", ", $type_allowed);
        $page['erreur'][$nb_error]['message'] = text_replace($lang['match']['E_invalid_file_type'], $var);
        $nb_error++;
    }
    if ($_FILES['file']['size'] > MAX_FILE_SIZE) {
        $var['max_file_size'] = filesize_format(MAX_FILE_SIZE);
        $page['erreur'][$nb_error]['message'] = text_replace($lang['match']['E_invalid_file_size'], $var);
        $nb_error++;
    }
    if (!isset($_POST['separator']) or empty($_POST['separator'])) {
        $page['erreur'][$nb_error]['message'] = $lang['match']['E_empty_separator'];
        $nb_error++;
    }
    # there is no error : we upload the file and get its content
    if ($nb_error == 0) {
        if (isset($_POST['first_line'])) {
            $page['value_first_line'] = $_POST['first_line'];
        }
        $path_file = ROOT . "/" . FILE_FOLDER . "/import_match.csv";
        $copy_file = move_uploaded_file($_FILES['file']['tmp_name'], $path_file);
        if (!$copy_file) {
Example #3
0
function getFolderMeta($path)
{
    //=============================================
    jsonStart();
    $path = mysql_escape_string($path);
    $size = filesize_format(get_size($path));
    $name = basename($path);
    jsonAdd("\"name\": \"{$name}\", \"size\": \"{$size}\"");
    echo jsonReturn('getFolderMeta');
}
Example #4
0
    echo $v['name'];
    ?>
">
	  <?php 
    if ($this->_cache['show_mode'] == 2 && in_array(fileext($v['path']), array('jpg', 'jpeg', 'png', 'gif', 'bmp'))) {
        ?>
<img src="<?php 
        echo ATTACHMENT_URL . $v['path'];
        ?>
" height="60" /> <?php 
    }
    echo $v['name'];
    ?>
</a></td>
	  <td><?php 
    echo filesize_format($v['filesize']);
    ?>
</td>
      <td><?php 
    echo time_format($v['addtime']);
    ?>
</td>
      <td><?php 
    echo $v['userid'];
    ?>
</td>
	  <td><?php 
    echo $v['usertimes'];
    ?>
</td>
	  <td><input name="tagsinput" data-id="<?php 
Example #5
0
                    /*-------------------------------------------------------------------------*/
                    $names = [];
                    $dir = opendir('../media');
                    while ($name = readdir($dir)) {
                        if ($name !== '.' && $name !== '..') {
                            array_push($names, $name);
                        }
                    }
                    closedir($dir);
                    /*-------------------------------------------------------------------------*/
                    sort($names);
                    foreach ($names as $name) {
                        $size = filesize("../media/{$name}");
                        $date = filemtime("../media/{$name}");
                        $NAME = $cms->escapeHTML($name);
                        $SIZE = filesize_format($size);
                        $DATE = filemtime_format($date);
                        print "\t\t\t\t\t\t\t<tr>\n";
                        print "\t\t\t\t\t\t\t\t<td><a href=\"/media/{$name}\" target=\"_blank\">{$NAME}</a></td>\n";
                        print "\t\t\t\t\t\t\t\t<td>{$SIZE}</td>\n";
                        print "\t\t\t\t\t\t\t\t<td>{$DATE}</td>\n";
                        print "\t\t\t\t\t\t\t\t<td><a href=\"javascript:renFile('{$NAME}')\"><i class=\"fa fa-pencil text-primary\"></i></a></td>\n";
                        print "\t\t\t\t\t\t\t\t<td><a href=\"javascript:delFile('{$NAME}')\"><i class=\"fa fa-trash text-danger\"></i></a></td>\n";
                        print "\t\t\t\t\t\t\t</tr>\n";
                    }
                    /*-------------------------------------------------------------------------*/
                    ?>
						</tbody>
					</table>
<?php 
                } else {
Example #6
0
if (!empty($tab_file)) {
    sort($tab_file);
}
foreach ($tab_file as $f) {
    $type = strtolower(substr($f, strrpos($f, ".") + 1));
    if (in_array($type, $type_allowed)) {
        $page['file'][$j]['i'] = $j;
        $page['file'][$j]['name'] = $f;
        $page['file'][$j]['url'] = $page['root_url'] . $page['current_folder'] . $f;
        $page['file'][$j]['L_select'] = $lang['file']['select_file'];
        $page['file'][$j]['L_delete'] = $lang['file']['delete'];
        $page['file'][$j]['link_delete'] = '';
        if ($right_user['delete_file']) {
            $page['file'][$j]['link_delete'] = convert_url("index.php?r=" . $lang['general']['idurl_file'] . "&v1=file_manager&mode=delete&file=" . $page['current_folder'] . $f . $fin_url, 0);
        }
        $page['file'][$j]['size'] = filesize_format(@filesize($rep . $f));
        $page['file'][$j]['width'] = "";
        $page['file'][$j]['height'] = "";
        if (in_array($type, $type_allowed)) {
            $page['file'][$j]['type'] = $type;
        } else {
            $page['file'][$j]['type'] = "unknown";
        }
        $page['file'][$j]['L_view'] = $lang['file']['view_image'];
        $page['file'][$j]['category'] = "";
        if (in_array($type, $type_allowed_image)) {
            $page['file'][$j]['category'] = "image";
        }
        if (in_array($type, $type_allowed_video)) {
            $page['file'][$j]['category'] = "video";
        }
Example #7
0
File: my.php Project: vcgato29/poff
/**
 * filemanager page
 *
 * @return string
 */
function action_filemanager()
{
    if (isset($_REQUEST['filepath']) && is_readable($_REQUEST['filepath']) && !demo) {
        header('Content-Type: ' . getmimetype($_REQUEST['filepath']));
        header('Content-Disposition: filename=' . basename($_REQUEST['filepath']));
        readfile($_REQUEST['filepath']);
        exit;
    }
    $output = '<h1>filemanager</h1>';
    #$default_dir = dirname(__FILE__);
    $default_dir = '.';
    $current_dir = isset($_REQUEST['dir']) ? $_REQUEST['dir'] : $default_dir;
    #if(demo && is_forbidden($current_dir))
    if (demo && strlen(realpath($current_dir)) < strlen(realpath(dirname(__FILE__)))) {
        $current_dir = $default_dir;
    }
    if (!is_dir($current_dir)) {
        $current_dir = $default_dir;
    }
    $current_dir = realpath($current_dir);
    if (is_writeable($current_dir) && !demo) {
        if (isset($_FILES['uploadfile'])) {
            if ($_FILES['uploadfile']['error'] == UPLOAD_ERR_OK && move_uploaded_file($_FILES['uploadfile']['tmp_name'], add_slash_if_needed($current_dir) . $_FILES['uploadfile']['name'])) {
                $output .= '<p class="notice">File has been uploaded.</p>';
            } else {
                $err = $_FILES['uploadfile']['error'];
                $upload_errors = array(UPLOAD_ERR_OK => 'upload ok.', UPLOAD_ERR_INI_SIZE => 'file was bigger than allowed in php.ini', UPLOAD_ERR_FORM_SIZE => 'file was bigger that allowed with MAX_FILE_SIZE on form', UPLOAD_ERR_PARTIAL => 'upload was partial', UPLOAD_ERR_NO_FILE => 'no file', 6 => 'temp dir not found');
                $output .= '<p class="error">Upload failed, err #' . $err . ': "' . $upload_errors[$err] . '"</p>';
            }
        }
        if (isset($_POST['newfilename']) && in_array($_POST['newfiletype'], range(1, 2))) {
            $newpath = add_slash_if_needed($_REQUEST['dir']) . $_POST['newfilename'];
            if ($_POST['newfiletype'] == 1) {
                if (touch($newpath)) {
                    $output .= '<p class="notice">File has been created.</p>';
                } else {
                    $output .= '<p class="error">File creating failed.</p>';
                }
            } else {
                if (mkdir($newpath)) {
                    $output .= '<p class="notice">Folder has been created.</p>';
                } else {
                    $output .= '<p class="error">Error: folder creating failed.</p>';
                }
            }
        }
    }
    $files = $folders = array();
    $d = dir($current_dir);
    if (is_object($d)) {
        while (false !== ($file = $d->read())) {
            $path = add_slash_if_needed($current_dir) . $file;
            if (is_file($path)) {
                $files[$path] = $file;
            } else {
                $folders[$path] = $file;
            }
        }
        $d->close();
    }
    if (demo) {
        $output .= '<p class="error">You can browse only current folder and its subfolders in demo mode</p>';
    }
    $output .= '<form action="' . self . '" method="post">
	<input type="text" name="dir" value="' . $current_dir . '" size="50">
	<input type="hidden" name="filem" value="1">
	<input type="submit" value=" cd ">
	</form>';
    if (is_writeable($current_dir)) {
        // upload form
        $output .= '<form action="' . self . '" method="post" enctype="multipart/form-data">';
        $output .= '<input type="file" name="uploadfile">';
        $output .= '<input type="submit" value="upload">';
        $output .= html_hidden(array('dir' => $current_dir, 'filem' => 1));
        $output .= '</form>';
        // new file/folder form
        $output .= '<form action="' . self . '" method="post">';
        $output .= html_selectbox('newfiletype', array(1 => 'file', 2 => 'folder'), 1);
        $output .= '<input type="text" name="newfilename">';
        $output .= html_hidden(array('dir' => $current_dir, 'filem' => 1));
        $output .= '<input type="submit" value="create">';
        $output .= '</form>';
    }
    $i = 1;
    // flag for css style
    $output .= '<table>';
    $output .= '<tr class="table_header">
		<th>filename</th>
		<th>size</th>
		<th>perms</th>
		<th>how old</th>
		<th>actions</th>
	</tr>';
    if (count($folders)) {
        natcasesort($folders);
        foreach ($folders as $fop => $fo) {
            $i = !$i;
            $row_css = $i ? 'class="table_even_row"' : 'class="table_odd_row"';
            $output .= '<tr ' . $row_css . '>
				<td>[ ' . html_encode_link($fo, self, array('filem' => 1, 'dir' => add_slash_if_needed($current_dir) . $fo)) . ' ]</td>
				<td>&nbsp;</td>
				<td>' . getperms($fop) . '</td>
				<td align="right" title="' . date('Y-m-d H:i:s', filemtime($fop)) . '">' . how_old(filemtime($fop)) . '</td>
				<td></td>
			</tr>';
        }
    }
    if (count($files)) {
        natcasesort($files);
        foreach ($files as $fip => $fi) {
            $i = !$i;
            $row_css = $i ? 'class="table_even_row"' : 'class="table_odd_row"';
            $output .= '<tr ' . $row_css . '>
				<td>' . html_encode_link($fi, self, array('filem' => 1, 'filepath' => $fip, 'cmd' => 'view')) . '</td>
				<td align="right">' . filesize_format(filesize($fip)) . '</td>
				<td>' . getperms($fip) . '</td>
				<td align="right" title="' . date('Y-m-d H:i:s', filemtime($fip)) . '">' . how_old(filemtime($fip)) . '</td>
				<td>' . (is_writeable($fip) ? html_encode_link('edit', self, array('editfile' => 1, 'path' => $fip)) : '') . (is_readable($fip) && eregi('php$', $fip) ? ' ' . html_encode_link('analyze', self, array('analyzefile' => 1, 'filepath' => $fip)) : '') . '</td>
			</tr>';
        }
    }
    return $output .= '</table>';
}
Example #8
0
    }
    $Tables = substr($Tables, 0, -1);
    if ($_POST['ActionType'] == 1) {
        $ActionSql = "OPTIMIZE TABLE " . $Tables;
    }
    if ($_POST['ActionType'] == 2) {
        $ActionSql = "REPAIR TABLE " . $Tables;
    }
    $DB->connect($mysql_host, $mysql_user, $mysql_pass, $mysql_dbname, '');
    $DB->query($ActionSql);
    $DB->close();
    die("<script>alert('操作成功');</script>");
}
$DB->connect($mysql_host, $mysql_user, $mysql_pass, $mysql_dbname, '');
$dbTable = $DB->fetch_all("SHOW TABLE STATUS");
$DB->close();
$mysqlTable = array();
foreach ($dbTable as $table) {
    if (substr($table['Name'], 0, strlen($mysql_prefix)) == $mysql_prefix) {
        $mysqlTable[] = array("Name" => $table['Name'], "Comment" => $table['Comment'], "Rows" => $table['Rows'], "Index_length" => filesize_format($table['Index_length']), "Data_length" => filesize_format($table['Data_length']));
    }
}
$tmp =& myTpl("db_manage.html");
$tmp->assign('codeName', $code_name);
$tmp->assign('codeVersion', $code_version);
$tmp->assign('siteName', $site_name);
$tmp->assign('siteDomain', $site_domain);
$tmp->assign('siteCatalog', $site_catalog);
$tmp->assign('dbBakPath', $dbBakPath);
$tmp->assign('dbTable', $mysqlTable);
$tmp->output();
?>
">
						<td class="label">File Type:</td>
						<td class="data"><?php 
echo $logResult["filetype"];
?>
</td>
					</tr>
					<tr class="<?php 
$i++;
echo $dss_rowStyles[$i % 2];
?>
">
						<td class="label">File Size:</td>
						<td class="data"><?php 
echo filesize_format($logResult["filesize"]);
?>
</td>
					</tr>
					<tr class="<?php 
$i++;
echo $dss_rowStyles[$i % 2];
?>
">
						<td class="label">File Name:</td>
						<td class="data"><?php 
echo $logResult["filename"];
?>
</td>
					</tr>
					<tr class="<?php 
Example #10
0
    }
}
foreach ($results as $file) {
    $info = stat("{$file}");
    $comment = "";
    $pathinfo = pathinfo($file);
    if (is_file("{$pathinfo['dirname']}/.{$pathinfo['basename']}")) {
        $comment = file_get_contents("{$pathinfo['dirname']}/.{$pathinfo['basename']}");
    }
    $name = "";
    if ($search_pattern) {
        $name = preg_replace("/^files\\/(" . str_replace('/', '\\/', $dir) . ")?\\/?/", '', $file);
    } else {
        $name = array_shift(array_reverse(explode('/', $file)));
    }
    $file = array('name' => $name, 'size' => $info[7], 'mdate' => $info[9], 'cdate' => $info[10], 'nicesize' => filesize_format($info[7]), 'nicemdate' => date($time_format, $info[9]), 'nicecdate' => date($time_format, $info[10]), 'comment' => $comment, 'type' => filetype("{$file}"));
    if ($file[type] == "dir" || $file[type] == 'link') {
        $dirs[] = $file;
    } else {
        $files[] = $file;
    }
}
if ($dirs[0]) {
    array_key_multi_sort($dirs, strtolower($sort));
    if ($desc) {
        $dirs = array_reverse($dirs);
    }
}
if ($files[0]) {
    array_key_multi_sort($files, strtolower($sort));
    if ($desc) {
Example #11
0
function uploadSmart()
{
    global $uploadDir;
    if (!file_exists($uploadDir . "stats_" . session_id() . ".txt")) {
        jsonStart();
        jsonAdd("\"percent\": 0, \"percentSec\": 0, \"speed\": \"0\", \"secondsLeft\": \"0\", \"done\": \"false\"");
        echo jsonReturn("bindings");
        exit;
    }
    $lines = file($uploadDir . "stats_" . session_id() . ".txt");
    jsonStart();
    $percent = round($lines[0] / 100, 3);
    $percentSec = round($lines[1] / 100, 4);
    $speed = filesize_format($lines[2]) . 's';
    $secondsLeft = secs_to_string(round($lines[3]));
    $size = filesize_format($lines[4]) . 's';
    if ($percent == 1) {
        // cleanup time
        if (isset($_SESSION['uploadPath'])) {
            $path = $_SESSION['uploadPath'];
            $userpath = getUserPath($path) . $path;
            $sessionid = session_id();
            $dh = opendir($uploadDir);
            while (($file = readdir($dh)) !== false) {
                $sessionlen = strlen(session_id());
                if (substr($file, 0, $sessionlen) == session_id()) {
                    $filename = substr($file, $sessionlen + 1);
                    $uploadfile = $filename;
                    $i = 1;
                    while (file_exists($userpath . '/' . $uploadfile)) {
                        $uploadfile = $i . '_' . $filename;
                        $i++;
                    }
                    if (file_exists("{$uploadDir}{$file}") && !rename("{$uploadDir}{$file}", "{$userpath}/{$uploadfile}")) {
                        echo "Error";
                    }
                }
            }
            closedir($dh);
            if (file_exists($uploadDir . "stats_" . session_id() . ".txt")) {
                unlink($uploadDir . "stats_" . session_id() . ".txt");
            }
            if (file_exists($uploadDir . "temp_" . session_id())) {
                unlink($uploadDir . "temp_" . session_id());
            }
        }
        $done = "true";
    } else {
        $done = "false";
    }
    jsonAdd("\"percent\": {$percent}, \"size\": \"{$size}\",\"percentSec\": {$percentSec}, \"speed\": \"{$speed}\", \"secondsLeft\": \"{$secondsLeft}\", \"done\": \"{$done}\"");
    echo jsonReturn("bindings");
}
Example #12
0
<?php

require dirname(__FILE__) . "/global.php";
if (isset($_GET['do']) && $_GET['do'] == "logout") {
    setcookie("adminSecure", "", time() - 36000, $cookie_path, $cookie_domain);
    header("location:../");
    exit;
}
$DB->connect($mysql_host, $mysql_user, $mysql_pass, $mysql_dbname, '');
$mysql_version = $DB->version();
$dbsize = 0;
$tables = $DB->fetch_all("SHOW TABLE STATUS");
foreach ($tables as $table) {
    if (substr($table['Name'], 0, strlen($mysql_prefix)) == $mysql_prefix) {
        $dbsize += $table['Data_length'] + $table['Index_length'];
    }
}
$DB->close();
$systemInfo = array("root" => isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : '', "os" => PHP_OS, "web" => explode("/", $_SERVER['SERVER_SOFTWARE']), "php" => PHP_VERSION, "mysql" => $mysql_version, "dbsize" => filesize_format($dbsize));
$tmp =& myTpl("index.html");
$tmp->assign('codeName', $code_name);
$tmp->assign('codeVersion', $code_version);
$tmp->assign('siteName', $site_name);
$tmp->assign('siteDomain', $site_domain);
$tmp->assign('siteCatalog', $site_catalog);
$tmp->assign('systemInfo', $systemInfo);
$tmp->output();
?>
">
						<td class="label">File Type:</td>
						<td class="data"><?php 
echo $itemResult["filetype"];
?>
</td>
					</tr>
					<tr class="<?php 
$i++;
echo $dss_rowStyles[$i % 2];
?>
">
						<td class="label">File Size:</td>
						<td class="data"><?php 
echo filesize_format($itemResult["filesize"]);
?>
</td>
					</tr>
					<tr class="<?php 
$i++;
echo $dss_rowStyles[$i % 2];
?>
">
						<td class="label">File Name:</td>
						<td class="data"><?php 
echo $itemResult["filename"];
?>
</td>
					</tr>
					<tr class="<?php 
Example #14
0
                $DB->query($sql);
                $sql = "";
            } else {
                if (!ereg("^(//|--)", $line)) {
                    $sql .= $line;
                }
            }
        }
        $DB->close();
        fclose($fp);
        die("<script>alert('还原成功');</script>");
    }
}
$sqlFileArr = array();
if ($handle = @opendir($dbBakPath)) {
    while (($file = readdir($handle)) !== false) {
        $fileType = strtolower(strrchr($dbBakPath . $file, "."));
        if ($fileType == ".sql") {
            $sqlFileArr[] = array("file" => $file, "size" => filesize_format(filesize($dbBakPath . $file)), "time" => date('Y-m-d H:i:s', filectime($dbBakPath . $file)));
        }
    }
    closedir($handle);
}
$tmp =& myTpl("db_import.html");
$tmp->assign('codeName', $code_name);
$tmp->assign('codeVersion', $code_version);
$tmp->assign('siteName', $site_name);
$tmp->assign('siteDomain', $site_domain);
$tmp->assign('siteCatalog', $site_catalog);
$tmp->assign('sqlFile', $sqlFileArr);
$tmp->output();
{
    echo $s . '<br />';
    ob_flush();
    flush();
}
$filename = $_GET['f'];
$filepath = GEDCOM_DIR . $filename;
# initialize gedcom parser
outputnow('Initializing gedcom parser...');
require_once CORE_PATH . 'gedcom.class.php';
$gedcom = new GedcomParser();
# analyze gedcom
outputnow('Analyzing ' . $filename . '...');
$gedcom->Open($filepath);
$gedcom->GetStatistics();
#display results of analysis
outputnow('');
outputnow('Size: ' . filesize_format($gedcom->fsize));
outputnow('Lines: ' . number_format($gedcom->lines));
outputnow('Individuals: ' . number_format($gedcom->individual_count));
outputnow('Families: ' . number_format($gedcom->family_count));
outputnow('Sources: ' . number_format($gedcom->source_count));
outputnow('Notes: ' . number_format($gedcom->note_count));
outputnow('');
$yes = '<a href="' . $_SERVER['PHP_SELF'] . '?m=gedcom_process&f=' . $filename . '">Yes</a>';
$no = '<a href="' . BASE_SCRIPT . '?m=gedcom" target="_parent">No</a>';
outputnow('Are you sure you want to import this file?');
outputnow($yes);
outputnow($no);
?>
</span>