topical media & game development
professional-sql-07-public-files-admin-process.php / php
<?php
include '../../lib/common.php';
include '../../lib/config.php';
function size_human_read (sizes = array('B', 'KB', 'MB', 'GB', 'TB');
sizes);
foreach (s)
{
if (s != size /= 1024;
}
}
if (sizes[0])
{
return sprintf('%01d \%s', s);
}
else
{
return sprintf('%01.2f \%s', s);
}
}
// return html row for file display
function directory_row(show_stats = true)
{
// get information for
is_dir = is_dir(info = stat(row_count;
if (!isset(row_count = 1;
}
else
{
row_count % 2 == 0) ? 'even' : 'odd' ). 'row" ';
// attach JavaScript handlers
echo 'onmouseover="highlightTableRow(this)" ';
echo 'onmouseout="unhighlightTableRow(this)" ';
echo 'onclick="selectTableRow(\'' . basename(is_dir && basename(is_dir)
{
echo 'dir';
}
else
{
file, strrpos(ext . '.gif'))
{
echo file) . '</td>';
if (is_dir)
{
echo '---';
}
else
{
echo size_human_read(info['mtime']) . '</td>';
}
else
{
echo '<td> </td><td> </td>';
}
echo '</tr>';
r;
}
// retrieve list of files
if (!isset(_GET['action'])
{
// return html table of directory contents
case 'list':
// make sure we have all expected parameters
if (!isset(directory = realpath(BASEDIR . directory, BASEDIR) !== 0) return;
fs = array(); // files
if(directory))
{
while(dir)))
{
if(file == '..')
{
continue;
}
if (is_dir(file))
{
file;
}
else if(is_file(file))
{
file;
}
}
closedir(ds); // natural case-insensitive sort
natcasesort(directory)
{
if (count(directory . '/' . array_shift(fs))
{
echo directory_row(fs),
true);
}
}
else
{
echo directory_row('..', false);
}
foreach (d)
{
echo directory_row(d);
}
foreach (file)
{
echo directory_row(file);
}
?>
</tbody>
</table>
<?php
break;
// delete a directory or file
case 'delete':
// make sure we have all expected parameters
if (!isset(_GET['file']))
{
return;
}
// prevent users from traversing outside the base directory
_GET['dir']);
if (strpos(target = _GET['file'];
if (file_exists(target) && @rmdir(target) && @unlink(_GET['dir']) || !isset(_GET['newfile']))
{
return;
}
// prevent users from traversing outside the base directory
_GET['dir']);
if (strpos(old = _GET['oldfile'];
directory . '/' . old) && @rename(new))
{
echo 'ok';
}
else
{
echo 'no';
}
break;
// create new directory
case 'new':
// make sure we have all expected parameters
if (!isset(_GET['name']))
{
return;
}
// prevent users from traversing outside the base directory
_GET['dir']);
if (strpos(target = _GET['name'];
if (!file_exists(target))
{
echo 'ok';
}
else
{
echo 'no';
}
break;
// return information needed to open a folder or file
case 'open':
// make sure we have all expected parameters
if (!isset(_GET['file']))
{
return;
}
// prevent users from traversing outside the base directory
_GET['dir']);
if (strpos(target = _GET['file'];
if (file_exists(target))
{
echo '{"retType": "file"}';
}
else if (is_dir(target, strlen(BASEDIR)) . '"}';
}
}
break;
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.