3v4l.org

run code in 300+ PHP versions simultaneously
<?php include_once('classes/Connection.php'); $conn = Classes_DbConnection::getInstance(); $fileNumber = 0; // Read directory files into array $dirPath = '../media_data'; $dirFiles = array(); if ($handle = opendir($dirPath)) { while ($file = readdir($handle)) { $pathInfo = pathinfo($file); if (!is_dir("../media_data/" . $pathInfo['basename'])) { // Get media id, if there is one $idMedia = 0; $splitFilename = explode('_', $pathInfo['filename']); if($splitFilename[0] = '000' && is_numeric($splitFilename[1])) { $idMedia = $splitFilename[1]; } else if($splitFilename[0] = '000' && $splitFilename[0] = 'richtext' && is_numeric($splitFilename[2])) { $idMedia = $splitFilename[2]; } $pathInfo['filesize'] = filesize($dirPath . '/' . $file); $dirFiles[$idMedia][] = $pathInfo; } } } $clientsMedias = array(); foreach ($dirFiles as $idMedia => $files) { if ($idMedia != 0) { // @TODO: Code to avoid processing a files more than once $mediaClients = $conn->getByQuery(" SELECT mrc.id_media, mrc.id_client, mrc.status, mr.title, mr.media, mr.filename, mr.filenamePreview, mr.filenameImage FROM dw_media_resources_clients mrc inner join dw_media_resources mr on mrc.id_media = mr.id WHERE id_media = {$idMedia} "); if (!empty($mediaClients)) { foreach($mediaClients as $media) { $clientsMedias[$media['id_client']][$media['id_media']] = $media; $clientsMedias[$media['id_client']][$media['id_media']]['files'] = $files; } } } } ?> <pre> <?//= print_r($clientsMedias) ?> </pre> <? ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta http-equiv="Content-Language" content="en"/> <meta name="viewport" content="width=device-width, minimum-scale=1.0, maximum-scale=1.0" /> <title>Izel Application Reports</title> <meta name="title" content="Izel Application Reports"/> <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'> <link rel="shortcut icon" href="images/favicon.png" /> <!-- css --> <link rel="stylesheet" href="css/normalize-custom.css" type="text/css" /> <link rel="stylesheet" href="css/styles.css" type="text/css" /> <!-- js --> <script src="js/jquery-1.8.2.min.js"></script> <script src="js/modernizr.js"></script> <script src="js/functions.js"></script> </head> <body> <div class="placer"> <h1>Storage Report</h1> <? foreach ($clientsMedias as $clientId => $clientMedia) { $clientTotalFilesize = 0; $clientTotalFilenumber = 0; ?> <!-- <h2><?= $clientId ?></h2> --> <? foreach ($clientMedia as $media) { $media_type; if($media['media'] == 2 /* Video */){ $media_type = '&#127916;'; } else if($media['media'] == 5 /* Article */ ){ $media_type = '&#59185;'; } else if($media['media'] == 4 /* Image */ ){ $media_type = '&#127748;'; } else if($media['media'] == 3 /* Audio */ ){ $media_type = '&#127925;'; } else if($media['media'] == 6 /* Rich text */ || $media['media'] == 7 /* Blog post */){ $media_type = '&#128240;'; } else if($media['media'] == 1 /* Other */ ){ $media_type = '&#128229;'; } ?> <!-- <table class="report"> <tr> <th class="cell_icon"><i><?=$media_type?></i></th> <th class="cell_title" colspan="3">ID #<?= $media['id_media'] ?> &middot; <?= $media['title'] ?></th> </tr> --> <? foreach ($media['files'] as $fileNumber => $mediaFile) { $filesize = $mediaFile['filesize'] / 1024 / 1024; $clientTotalFilesize += $mediaFile['filesize']; $clientTotalFilenumber += 1; ?> <!-- <tr> <td class="cell_icon icon_success"><i>&#10003;</i></td> <td class="cell_filename"><?= $mediaFile['basename'] ?></td> <td class="cell_filesize"><?= $filesize ?></td> <td>Status</td> </tr> --> <? } ?> <!-- </table> --> <? } ?> <table class="report"> <tr> <th class="cell_icon"><i>&#128203;</i></th> <th class="cell_title" colspan="3">CLIENT ID #<?= $clientId ?> &middot; Nombre de cliente</th> </tr> <tr> <td class="cell_icon"><i>&#57349;</i></td> <td class="cell_filename"><?= $clientTotalFilenumber ?> Archivos</td> <td class="cell_filesize" colspan="2"><?= $clientTotalFilesize / 1024 / 1024 ?> Mb.</td> </tr> </table> <? } ?> </div> </body> </html>

preferences:
49.5 ms | 402 KiB | 5 Q