PHP List mp3’s in Directory & Read Tags
This will search your $directory for mp3 files, grab two tags from the mp3 (more can be added to grab).
function list_all_mp3 () { $directory = 'public/downloads/audio/'; $results = array(); $handler = opendir($directory); while ($file = readdir($handler)) { if ($file != '.' && $file != '..') { $mp3 = $file; $filesize = filesize($directory . $mp3); $fh = fopen($directory . $mp3, "r"); fseek($fh, -128, SEEK_END); $tag = fread($fh, 3); if($tag == "TAG") { $title = trim(fread($fh, 30)); $speaker = trim(fread($fh, 30)); } else die("MP3 file does not have any ID3 tag"); fclose($fh); echo "$directory$mp3 - $title \n"; echo "Speaker: $speaker \n"; } } closedir($handler); }
PHP Get Filesize
Here is an easy to use function to determine the file size of any file in PHP. Just include this function on a page..
function filesize($bytes) { $size = $bytes / 1024; if($size < 1024) { $size = number_format($size, 2); $size .= ' KB'; } else { if($size / 1024 < 1024) { $size = number_format($size / 1024, 2); $size .= ' MB'; } else if ($size / 1024 / 1024 < 1024) { $size = number_format($size / 1024 / 1024, 2); $size .= ' GB'; } } return $size; }
To get the filesize just apply the function:
filesize('filename.mp3');
Basic Document
To make a basic HTML page follow these steps:
1. Open a text editor such as Notepad (Don't use Word or any RTF editor)
2. Make a new document and save it as index.html
2.1 Note: Saving it as .htm or .html doesn't matter, it's more common to use .html so use that.
3. Insert the code below:
<html><head> <title>Title of Page</title></head> <body> All My Content Goes Here </body></html>
4. Now open the file and you have a web page.
Change Some Settings
Lets add some CSS (Cascading Style Sheets) to the index.html page:
<html> <head>
<title>Title of Page</title> </head>
<style type="text/css">body { background-color: silver; color: gray: font-family: Arial, sans-serif; font-size: 14px;</style>
<body>
<h1>An Important Heading</h1> <p>All My Content Goes HereNow look at how text has changed!</p> </body> </html>
Done!
CSS Basics
You must learn CSS if you want to make websites!
1. Find the folder you made index.html in
2. Make a new text document and save it as style.css
3. Open index.html in your text editor,
3.1 Go between the <head></head> tags and add:
<link rel="stylesheet" type="text/css" href="style.css" />
4. Now the style sheet file is linked to your index.html page!
Go ahead and close your index.html file and open your style.css file.
Standard Formatting
Here is a good way to standardize your CSS document:
* {margin: 0; padding: 0}body { background-color: #fff; color: #000; font-family: 'Trebuchet MS', sans-serif; font-size: 15px;}
The above will apply everything to entire document.
Change all the <p> tags
The beauty of CSS is that you can change one line and it affects every html page of yours, here is how you do the tag:
p { padding: 5px; border: 1px solid red;}
Elements, Classes, and ID's
In CSS you apply rules to one of the 3 of these, Classes and ID's are things you set,
body, p, em = Elements, any HTML tag.
#name = ID, a pound sign with any name you want to give it
.name = Class, a period with any name you want to give it.
To apply an ID or class to an HTML element you would do it this way:
<a class="name" href="test.html">Test</a> -- And all settings for .name in CSS will go to this Anchor.
<a id="name" href="text.html">Test</a> -- Same for this, but you only want to use ID's for things that are used once, such as Layout pieces.
CSS Borders
Here is a CSS Border in four declarations:
<div style="border-left: 1px solid red; border-right: 1px solid red; border-top: 1px solid red; border-bottom: 1px solid red;">This has a border</div>
Rather than do all that you can do one declaration
<div style="border: 1px solid red;">Text Here</div>
If you want to take the border off the sides:
<div style="border: 1px solid red; border-left: none; border-right: none;">Text Here</div>
