Skip to content

Instantly share code, notes, and snippets.

@bitwiser
Last active August 29, 2015 13:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitwiser/9294739 to your computer and use it in GitHub Desktop.
Save bitwiser/9294739 to your computer and use it in GitHub Desktop.
<?php
//Excersice 1
function getextension($file){
$path = pathinfo($file);
return $path['extension'];
}
$music = "";
if($handle = opendir('songs/')){
while(false !== ($entry = readdir($handle))){
if(getextension($entry)=='mp3'){
$music .= '<li class="mp3item">'.$entry.'</li>';
}
}
}
closedir($handle);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
<?php echo $music;?>
</ul>
</body>
</html>
<?php
//Excersice 2
function getextension($file){
$path = pathinfo($file);
return $path['extension'];
}
$music = "";
$playlist = "";
if($handle = opendir('songs/')){
while(false !== ($entry = readdir($handle))){
$ext = getextension($entry);
if($ext=='mp3'){
$music .= '<li class="mp3item">'.$entry.'</li>';
}else if($ext=='txt'){
$playlist .= '<li class="playlistitem">'.$entry.'</li>';
}
}
}
closedir($handle);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
<?php echo $music;?>
<?php echo $playlist;?>
</ul>
</body>
</html>
<?php
//Excersice 4
function getFileSize($dir,$file){
$c = 1024;
$size = filesize($dir.$file);
if($size<1024){
$size = $size." b";
}else if($size<=1048575){
$size = ($size/$c);
$size = sprintf("%.2f kb",$size);
}else{
$size = $size/($c*$c);
$size = sprintf("%.2f mb",$size);
}
return $size;
}
function getextension($file){
$path = pathinfo($file);
return $path['extension'];
}
$music = "";
$playlist = "";
if($handle = opendir('songs/')){
while(false !== ($entry = readdir($handle))){
$ext = getextension($entry);
if($ext=='mp3'){
$music .= '<li class="mp3item">'.$entry.' ('.getFileSize('songs/',$entry).')</li>';
}else if($ext=='txt'){
$playlist .= '<li class="playlistitem">'.$entry.'</li>';
}
}
}
closedir($handle);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<ul>
<?php echo $music;?>
<?php echo $playlist;?>
</ul>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment