Created
February 10, 2019 09:19
-
-
Save AlekVolsk/fa430f9d762d66f33c6a2192b39c9c5e to your computer and use it in GitHub Desktop.
SVG viewer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$list = []; | |
$err = ''; | |
$path = filter_input( INPUT_GET, 'path'); | |
if ( !$path ) | |
{ | |
$err = 'Path is empty'; | |
} | |
if ( !realpath( $path ) ) | |
{ | |
$err = 'Path is bad'; | |
} | |
if ( !$err ) | |
{ | |
$list = glob( $path . DIRECTORY_SEPARATOR . '*.svg' ); | |
} | |
if ( !$list ) | |
{ | |
$err = 'Folder is empty'; | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en-gb" dir="ltr"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
<base href="<?php echo 'http' . (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 's' : '') . '://' . $_SERVER['HTTP_HOST'] . '/'; ?>" /> | |
<title>SVG viewer</title> | |
<link rel="stylesheet" href="/uikit.min.css"> | |
<style> | |
.uk-grid > div { width: 200px; } | |
svg { max-width: 100px; } | |
</style> | |
<script src="/uikit.min.js"></script> | |
</head> | |
<body> | |
<div class="uk-section"> | |
<div class="uk-container uk-container-expand"> | |
<h1>SVG viewer</h1> | |
<?php if ( $err ) { ?> | |
<div class="uk-alert uk-aler-large uk-alert-warning uk-margin-large"><?php echo $err; ?></div> | |
<?php } else { ?> | |
<div class="uk-alert uk-aler-large uk-alert-primary uk-margin-large"><span class="uk-text-bold">Folder</span>: <?php echo $path; ?><br><span class="uk-text-bold">Count files</span>: <?php echo count( $list ); ?></div> | |
<div class="uk-child-width-auto" data-uk-grid data-uk-height-match="target:>div>.uk-flex"> | |
<?php foreach ( $list as $item ) { ?> | |
<div> | |
<div class="uk-flex uk-flex-center uk-flex-middle"><?php echo file_get_contents( $item ); ?></div> | |
<div class="uk-h4 uk-text-center uk-margin-small-top"><?php echo pathinfo( $item, PATHINFO_FILENAME ); ?></div> | |
</div> | |
<?php } ?> | |
</div> | |
<?php } ?> | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment