From 5f2a948f5551f0c168e6572ba500724bddf4c576 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sat, 21 Apr 2018 18:06:42 +0200 Subject: V2 W V0 M --- .gitignore | 2 +- class/class.aff.php | 39 ++++++++++++++----- class/class.app.php | 31 ++++++++++++++- class/class.media.php | 16 ++++++++ fn/fn.php | 25 ++++++++++++ public/css/style.css | 9 +++++ public/index.php | 2 + public/m/index.php | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 216 insertions(+), 12 deletions(-) create mode 100644 class/class.media.php create mode 100644 public/m/index.php diff --git a/.gitignore b/.gitignore index dd72d1d..c08da64 100644 --- a/.gitignore +++ b/.gitignore @@ -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 '

Home

'; echo ''; echo ''; foreach ($getlist as $item) { @@ -311,22 +312,40 @@ public function head($title) } + public function addmedia() + { + if ($this->session() >= 2) { + + ?> +

Ajouter un media

+ + + + + + + = 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 @@ + \ No newline at end of file diff --git a/fn/fn.php b/fn/fn.php index b075d57..65d14f4 100644 --- a/fn/fn.php +++ b/fn/fn.php @@ -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 @@ w +
+m \ 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 @@ +head($titre); + +// _____________________________________________________ A L E R T _______________________________________________________________ + +if (isset($_GET['message'])) { + echo '

' . $_GET['message'] . '

'; +} + + + +// ____________________________________________________ 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 ''; +$aff->nav($app); +$aff->addmedia(); + +echo '

Media

'; + +var_dump(2 ** 29); +var_dump(readablesize(2 ** 29)); + +echo '
'; + + +$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 ''; + echo '

' . $entry . '

'; + + echo 'width = ' . $width; + echo '
'; + echo 'height = ' . $height; + echo '
'; + echo 'filesize = ' . readablesize($filesize); + echo '
'; + + + echo 'image'; + + echo '
'; + } + } + closedir($handle); +} + +echo '
'; + +echo ''; + + +?> + + + -- cgit v1.2.3
titrerésumélienedit