我有一个php站点,它将zip文件的文件名分解为一些我可以放入表中的部分。我已将zip文件夹名称更改为例如:
dem-de_cache-1549763830-1549795108.zip
在表中断后,它看起来像:
http://xxxxxx/demka/multimod/dem-de_cache-1549763830-1549795108.zip
de_cache 49763830-1 725 kB Pobierz
地图,开始和停止会中断,并且无法正常运行。
当我的地图名称更长时,例如de_rats_1337,它看起来更糟
http://xxxxxx/demka/multimod/dem-de_rats_1337-1549793812-1549795108.zip
de_rats_1337 7-15497938 916 kB Pobierz
时间戳不能像我想要的那样工作
我还要在站点上按日期对文件进行排序,例如:文件的创建日期为11.02.2019时,文件的日期将相同。
我的网站示例:http://panel.tsklan.pl/demka
可以正常工作的示例网站:http://658751.node26.pukawka.pl/new.puk
我的代码:
<?php
// Laczenie z serwerem csgo
$ip = "xxxxxxxxxxx";
$port = "xxxxx";
$socket = socket_create(AF_INET, SOCK_DGRAM, 0);
$result = socket_connect($socket, $ip, $port);
if($result < 0)
echo "connect() failed.\nReason: ($result) \n";
$data = "\xFF\xFF\xFF\xFF\x54\x53\x6F\x75\x72\x63\x65\x20\x45\x6E\x67\x69\x6E\x65\x20\x51\x75\x65\x72\x79\x00";
socket_write($socket, $data, strlen($data));
$out = socket_read($socket, 4096);
$queryData = explode("\x00", substr($out, 6), 5);
$server['name'] = $queryData[0];
$servers = array (
'multimod' => array(
"title" => "$server['name']",
"prefix" => "dem"
)
);
$filesPerPage = 20;
# Size in bytes
function format_size($size, $round = 0)
{
$sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
for ($i=0; $size > 1024 && isset($sizes[$i+1]); $i++)
$size /= 1024;
return round($size, $round)." ".$sizes[$i];
}
function browse($path)
{
global $servers;
global $filesPerPage;
$data = array();
$page = $_GET['page'];
$page = !isset($page) || $page < 1 ? 0 : $page - 1;
$prefix = $servers[$path]['prefix'];
$prefix_sz = strlen($prefix) + 1;
$offsets = array(
map => $prefix_sz,
start => $prefix_sz + 11,
end => $prefix_sz + 23
);
if(is_dir($path))
{
$files = glob($path."/*.zip");
$count = count($files);
$pages = ceil( $count / $filesPerPage );
$page = $page >= $pages ? $pages - 1 : $page;
$begin = $count - ($page + 1) * $filesPerPage;
$end = $count - $page * $filesPerPage;
for($i = $begin < 0 ? 0 : $begin; $i < $end; ++$i)
{
$file = end( explode('/', $files[$i]) );
$name_end = strrpos($file, ".dem");
$name_end = $name_end === FALSE ? strrpos($file, ".zip") : $name_end;
$tmpfilesize = @filesize($files[$i]);
if($name_end === FALSE)
continue;
$tmp = array();
$tmp[map] = substr($file, $offsets[map], $name_end - $offsets[end]+1);
$tmp[start] = substr($file, $offsets[start], 10);
$tmp[end] = substr($file, $offsets[end], 10);
$tmp[file] = $file;
$tmp[size] = format_size($tmpfilesize);
$tmp[path] = $files[$i];
$data[] = $tmp;
}
$files = array();
}
echo '<!-- Lista dem -->
<div class="dema" id="d1"><table style="text-align: center;"><thead>
<tr><td colspan="6" class="day">Demka</td></tr>
<tr>
<th>URL</th>
<th>Mapa</th>
<th>Start</th>
<th>Stop</th>
<th>Rozmiar</th>
<th></th>
</tr></thead>';
if($count > 0)
{
foreach($data as $field)
{
echo '<tr>
<td class="url"><input type="text" value="http://'.$_SERVER[HTTP_HOST].''.$_SERVER[REQUEST_URI].''.$field[path].'"></td>
<td>'.$field[map].'</td>
<td>'.$field[start].'</td>
<td>'.$field[stop].'</td>
<td>'.$field[size].'</td>
<td class="dl"><a href="http://'.$_SERVER[HTTP_HOST].''.$_SERVER[REQUEST_URI].''.$field[path].'">Pobierz</a></td>
</tr>';
}
}
else
{
echo '<tr><td align="center">- Brak demek -</td></tr>';
}
echo '</table><br></div>';
if($pages > 1)
{
echo '<div class="pagination">';
for($i = 0; $i < $pages; ++$i)
{
if($pages > 10)
{
if($i > 2 && $i < $page - 1)
{
echo '...';
$i = $page - 1;
}
else
if($i > $page + 1 && $i > 2 && $i < $pages - 3)
{
echo '...';
$i = $pages - 3;
}
}
if($i != $page)
echo '<a href="?page='.($i + 1).'&server='.$path.'">'.($i + 1).'</a>';
else
echo '<span>'.($page + 1).'</span>';
}
echo '</div>';
}
}
?>