diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | class/class.aff.php | 39 | ||||
-rw-r--r-- | class/class.app.php | 31 | ||||
-rw-r--r-- | class/class.media.php | 16 | ||||
-rw-r--r-- | fn/fn.php | 25 | ||||
-rw-r--r-- | public/css/style.css | 9 | ||||
-rw-r--r-- | public/index.php | 2 | ||||
-rw-r--r-- | public/m/index.php | 104 |
8 files changed, 216 insertions, 12 deletions
@@ -2,4 +2,4 @@ vendor/* .vscode/* config.php error_log -w/img/* +public/media/* diff --git a/class/class.aff.php b/class/class.aff.php index c822a91..db0f59a 100644 --- a/class/class.aff.php +++ b/class/class.aff.php @@ -210,6 +210,7 @@ public function head($title) public function home2table($getlist) { if ($this->session() >= 2) { + echo '<h1>Home</h1>'; echo '<table>'; echo '<tr><th>titre</th><th>résumé</th><th>lien</th><th>edit</th></tr>'; foreach ($getlist as $item) { @@ -311,22 +312,40 @@ public function head($title) } + public function addmedia() + { + if ($this->session() >= 2) { + + ?> + <h1>Ajouter un media</h1> + <form action="./" method="post" enctype="multipart/form-data"> + <input type="hidden" name="action" value="addmedia"> + <input type="file" accept="*" name="media" required> + <input type="text" name="id" id="" placeholder="nom du fichier" required> + <input type="submit" value="envoi"> + </form> + <?php + + } + +} + //______________________________________________________ S E T _________________________________________________ - public function setsession($session) - { - if ($session <= 2 and $session >= 0) { - $session = intval($session); - $this->session = $session; - } +public function setsession($session) +{ + if ($session <= 2 and $session >= 0) { + $session = intval($session); + $this->session = $session; } +} //______________________________________________________ G E T _________________________________________________ - public function session() - { - return $this->session; - } +public function session() +{ + return $this->session; +} } diff --git a/class/class.app.php b/class/class.app.php index 961e51c..08a7202 100644 --- a/class/class.app.php +++ b/class/class.app.php @@ -70,7 +70,8 @@ class App public function getlister(array $selection, $tri) { $list = []; - if (is_array($selection) && is_string($tri) && strlen($tri) < 12) { + $option = ['datecreation', 'titre', 'id', 'intro', 'datemodif']; + if (is_array($selection) && is_string($tri) && strlen($tri) < 12 && in_array($tri, $option)) { $selection = implode(", ", $selection); @@ -153,6 +154,34 @@ class App $q->execute(); } + public function addmedia(array $file, $maxsize, $id) + { + $maxsize = 2 ** 40; + $id = strtolower(strip_tags($id)); + if (isset($file) and $file['media']['error'] == 0 and $file['media']['size'] < $maxsize) { + $infosfichier = pathinfo($file['media']['name']); + $extension_upload = $infosfichier['extension']; + $extensions_autorisees = array('jpeg', 'jpg', 'JPG', 'png', 'gif', 'mp3', 'mp4', 'mov', 'wav', 'flac'); + if (in_array($extension_upload, $extensions_autorisees)) { + if (!file_exists('../media/' . $id . '.' . $extension_upload)) { + + $uploadok = move_uploaded_file($file['media']['tmp_name'], '../media/' . $id . '.' . $extension_upload); + if ($uploadok) { + header('Location: ./?message=uploadok'); + } else { + header('Location: ./?message=uploaderror'); + } + } else { + header('Location: ./?message=filealreadyexist'); + + } + } + } else { + header('Location: ./?message=filetoobig'); + + } + } + //_________________________________________________________ S E S ________________________________________________________ public function login($pass) diff --git a/class/class.media.php b/class/class.media.php new file mode 100644 index 0000000..e144776 --- /dev/null +++ b/class/class.media.php @@ -0,0 +1,16 @@ +<?php + +class Media +{ + private $id; + private $extension; + private $type; + private $size; + private $height; + private $width; + +} + + + +?>
\ No newline at end of file @@ -52,5 +52,30 @@ function search($haystack, $debut, $fin) } +function readablesize(int $bytes) +{ + + $num = 5; + $location = 'tree'; + $format = ' %d %s'; + + + + if ($bytes < 2 ** 10) { + $num = $bytes; + $unit = 'o'; + } elseif ($bytes < 2 ** 20) { + $num = round($bytes / 2 ** 10, 1); + $unit = 'Kio'; + } elseif ($bytes < 2 ** 30) { + $num = round($bytes / 2 ** 20, 1); + $unit = 'Mio'; + } elseif ($bytes < 2 ** 40) { + $num = round($bytes / 2 ** 30, 1); + $unit = 'Gio'; + } + + return sprintf($format, $num, $unit); +} ?> diff --git a/public/css/style.css b/public/css/style.css index 7fb75c0..b0d8cc1 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -165,4 +165,13 @@ nav a { top: 0px; left: 0px; width: 8%; +} + +.thumbnail { + max-width: 100px; +} + +.grid { + display: flex; + flex-wrap: wrap; }
\ No newline at end of file diff --git a/public/index.php b/public/index.php index f935eed..40202a3 100644 --- a/public/index.php +++ b/public/index.php @@ -1,4 +1,6 @@ <html> <a href="/w/">w</a> +<br/> +<a href="/m/">m</a> </html>
\ No newline at end of file diff --git a/public/m/index.php b/public/m/index.php new file mode 100644 index 0000000..f5e101d --- /dev/null +++ b/public/m/index.php @@ -0,0 +1,104 @@ +<?php + +// _____________________________________________________ R E Q U I R E ________________________________________________________________ + + +$config = require('../../config.php'); + + + +require('../../fn/fn.php'); +require('../../class/class.art.php'); +require('../../class/class.app.php'); +require('../../class/class.aff.php'); +session(); +if (!isset($_SESSION['level'])) { + $level = 0; +} else { + $level = $_SESSION['level']; +} +$app = new App($config); +$aff = new Aff($level); + + + +// ______________________________________________________ H E A D _____________________________________________________________ +$titre = 'home'; +$aff->head($titre); + +// _____________________________________________________ A L E R T _______________________________________________________________ + +if (isset($_GET['message'])) { + echo '<h4>' . $_GET['message'] . '</h4>'; +} + + + +// ____________________________________________________ A C T I O N _______________________________________________________________ + + +if (isset($_POST['action'])) { + switch ($_POST['action']) { + case 'addmedia': + $app->addmedia($_FILES, 2 ** 30, $_POST['id']); + break; + } +} + +// ______________________________________________________ B O D Y _______________________________________________________________ + + + +echo '<body>'; +$aff->nav($app); +$aff->addmedia(); + +echo '<h1>Media</h1>'; + +var_dump(2 ** 29); +var_dump(readablesize(2 ** 29)); + +echo '<section class="grid">'; + + +$dir = "../media/"; + + +if ($handle = opendir($dir)) { + while (false !== ($entry = readdir($handle))) { + if ($entry != "." && $entry != "..") { + $fileinfo = pathinfo($entry); + + $filepath = '../media/' . $fileinfo['filename'] . '.' . $fileinfo['extension']; + + list($width, $height, $type, $attr) = getimagesize($filepath); + $filesize = filesize($filepath); + + echo '<span>'; + echo '<h2>' . $entry . '</h2>'; + + echo 'width = ' . $width; + echo '<br/>'; + echo 'height = ' . $height; + echo '<br/>'; + echo 'filesize = ' . readablesize($filesize); + echo '<br/>'; + + + echo '<img class="thumbnail" src="' . $filepath . '" title="' . $fileinfo['filename'] . '" alt="image">'; + + echo '</span>'; + } + } + closedir($handle); +} + +echo '</section>'; + +echo '</body>'; + + +?> + + + |