Topic: PHP code script for adding wmv files

I'm disabled;  not able to sit too long at a time and have been beating my head against the wall trying to learn PHP!  I would go to school but my disability makes that impossible!  So I have read numerous books; but have yet the knowledge I need!  I have a practice web site that uses wmv sermon files.  I upload them through SmartFtp into a sermons folder with 2 subdirectory folders; 1 for highspeed video and 1 for dialup.  I need a php script that would add the sermon through the folder directory and into the tr without me having to link them and code each individual file each time I upload one.  This is how the code looks that I link with:   <thead>
           <tr>
            <th>PLAY</th>
            <th>SERMONS</th>
            <th>Date 2007</th>
            <th>Presented By</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td><a href="sermons/highspeed/HE did it for you.wmv">PLAY</a></td>
            <td>HE did it for you</td>
            <td>September 23rd :11:30am</td>
            <td>Robert Tipton</td>
          </tr>
           <tr>
           <td><a href="sermons/highspeed/Morality.wmv">PLAY</a></td>
           <td>Morality</td>
           <td>September 23rd :6:45pm</td>
           <td>Robert Tipton</td>
           </tr>
     </thead>

So what i need is code that would add the sermon;  the title;  the date and the preacher to this code each time through the highspeed subdirectory of the sermons directory folder.  This site uses an external css file to style the table and page.  This is a practice site that i coded to help me learn with!address is www.cofchristsh.org  Our main church site is www.viewtheword.org in which I upkeep with the content end;  but originally paid a developer to code the site!  I would appreciate all and any advice plus help that you can offer me reguarding this stumbling block for me!!!  Thanks in advance for your help!

Re: PHP code script for adding wmv files

Have you thought of using flash to display the sermons?  It's generally much better supported than wmv...  You'd need to convert it to flash but there are a a couple of good (free) converters out there!  Just a thought...

I take it the site is hand coded and not in a cms?!  If it were in a cms, I'd have thought it would be quite simple to using custom fields or something to build parts of the code for you.   I use wordpress on my Church site and use this approach: http://www.minehead-baptist.com/sermons/  and if you look at the code, you'll see that there's no embeding or anything to do the player - just a link.  I use the magic of jquery to display the player.  http://malsup.com/jquery/media/ can do most audio and video in this format and might help you.

I'm sure some of the real php gurus will have some great ideas for backend things!

James Cooper --  God loving, banjo playing, geek!

Re: PHP code script for adding wmv files

Dwayne -

Scanning the directory with PHP will allow you to display 3 of the 4 fields you want.  The only one that it couldn't do is the presenter.  If you'd be okay with the filename, title (from the file name) and date, I can show you the code.

Your other option is set up a MySQL database to hold the information for you, then create a form to fill out and insert the data.  I can also show you code along those lines. [smile]

That's my 2 cents :^{>

Honored to Serve for Him - Tom ('Mas) Pickering <)><

Re: PHP code script for adding wmv files

maspick,   I would love to see your code!  I have MySQL database access;  but just like PHP;  I'm not there yet with the knowledge i need!  I would really like to see the code both ways;  but if i'm asking too much;  the first option will be okay!   Beggars can never be choosy!  Thank you!  Have a great day!

Re: PHP code script for adding wmv files

What I've done in the past is create file names for the media files such as "20090203_Preachersname.wmv" and use the PHP function substr() which lets you return a portion of the string. You create an array containing all of the media files in the directory and use the sort() command, which will sort them (duh...). Because they all start with a date, it will sort them in order of their date (2009 - 02 - 03).

Using substr($filename, 0, 8) will return 8 of the characters, starting from the 1st character in $filename.
Using substr($filename, 9) will return the rest of the characters, starting from the character after the underscore in $filename.

This is of course a very rough sample of how to do this, but I have some code that I used before I could send your way if you're interested.

Daniel Marino | www.iamdanielmarino.com

Re: PHP code script for adding wmv files

I think these answers are really good ones. I'll just add to the discussion mainly on learning PHP. You have the perfect scenario here where you have a project and you have the exact scope of what you want to accomplish. When you are first starting out, books are great but Google is an unstoppable force. Searching and gleaning code from others is invaluable. For instance... I put in "show files in directory php" into Google got some good results. Changing that search string slightly and getting a little more specific will really get you going.

What I have found is that while  progressing through being an entry level and even intermediate programmer... there are very few problems that someone else hasn't already encountered and written about.

Enjoy PHP!

I dream with an XML intereface

Re: PHP code script for adding wmv files

Dwayne -

Here's some code to pull the directory information:

	<tr>
		<th>PLAY</th>
		<th>SERMONS</th>
	</tr>
</thead>
<tbody>
<?
$dir = @ dir('./sermons/highspeed');
while ($entry = $dir -> read()) {
	if ($entry != '.' && $entry != '..' && strtolower(substr($entry, -3)) == 'wmv') {
?>
	<tr>
		<td><a href="sermons/highspeed/<? echo $entry; ?>">PLAY</a></td>
		<td><? echo substr($entry, 0, (strlen($entry) - 4)); ?></td>
	</tr>
<?
		} // each wmv file
	} // each directory entry
$dir -> close();
?>
</tbody>

The first line grabs the filenames from the sermon/highspeed directory and stores them in $dir.  You may need to experiment with how best to express that directory on your server.

The while loop checks for wmv files and creates a table row for each it finds.

Obviously, with the filenames you specified, there's no way to show the date or presenter.  If you incorporate dmarino's idea, you can then furnish more information that would be stored in the filename.

If you're not familiar yet with working with databases in PHP, code samples will not adequately explain what's needed.

Honored to Serve for Him - Tom ('Mas) Pickering <)><

Re: PHP code script for adding wmv files

Dmarino and Maspick and all others not mentioned!  I can already tell that i'm going to like this site!  You guys are great and i appreciate all your help more than you could ever know!!!  Thanks to you all;  im gaining a lot more understanding and i like both types of code that i have received!  While to be honest even though Dmarino's code will give me some different available options; i'm really going to have to get a better grip on php first!  I think that i can get started with Maspick's code and then with a little research and picking the other apart; i'll be able to use dmarino's as well!  Thanks so much and may *GOD* bless you!  Have a great day!!!!!!

Re: PHP code script for adding wmv files

To all who have helped me!!!   I wanted you to know that i love the code that Maspick gave me;  no offence intended for anyone else!  I'm sure that once i really come to grips with all the other code and help;  it will too be of great use to me!  It is not your code that is at fault;  but my lack of knowledge and understanding!  And hey;  everyone has to learn somewhere at sometime and i'm open to all your input!  Because frankly i need it and without other people;  we cannot learn!   Im still struggling through Dmarino's code and hope that i will be able to figure it out so that i can impliment it as well!  Just to let Maspick know;  within 5 mins time i had your code onto the view sermons now page of my site and it worked beatifully!  Just wish i could add the other <td> info i had; but all in good time!  my practice site is www.cofchristsh.org  Thanks once again to all of you!!!
________________________________________________________________________________________________________________________________

  To live is *CHRIST*;  to die is gain!

Re: PHP code script for adding wmv files

Dwayne -

Glad it worked for you. smile  I want to encourage you to study other developers' code a lot as you're learning.  When you find a piece of code that serves a purpose or improves upon something you already have, learn from it and start accumulating code snippets with explanatory comments to yourself so, 2 years later when you need that sort of thing again, you'll have a centralized place to look.  But always keep studying code.  I've been a programmer for 40 years and a web developer for nearly 14 years and I continue to browse code repositories for new ways to do things.  Since you are starting out, pay particular attention to OOP techniques.  It has been the hardest transition for this old dog trying to learn these new tricks. wink

Places to study code from would be The PHP Resource Index, Hot Scripts - PHP Scripts & Programs, OxyScripts are a few.

That's my 2 cents :^{>

Honored to Serve for Him - Tom ('Mas) Pickering <)><

Re: PHP code script for adding wmv files

Thank you for very much your encouragement!  It's great to be able to go onto a forum site that people are not trying to sell you software;  but instead want to help you for the common purpose of serving the *LORD* and enhancing your knowledge!  The Church congregation that i attend has a web-site that uses an admin section;  a cpanel section;  phpMYadmin for a MySQL database.  I originally went to a paid developer who set that site up so that i can put sermons on it through SmartFtp and upload images and make textual changes through the admin section.  It missed up and cost us a small fortune to have it repaired!  It uses an embeded media player and links to highspeed and dialup sermons videos.  So this is what got me started and interested in web design.  I have a WAMP set up on my laptop and have used the dump file from that site to create the datasbase tables and I have all the code;  but i cannot get it to work; much less figure it all out!  Maybe all in due time!  I'm not sure about all the MySQL stuff or how to use it!  There is a tremendous amount of files!  Too much for me at this point!  Thank you for the links above and the help that you have already given me!  May *GOD* bless you!
________________________________________________________________________________________________________________________________

                                                   To live is *CHRIST*;   And to die is gain!

Re: PHP code script for adding wmv files

Mas,  I'm continuing on;  to continue on!  I intend on learning as much as i can because i think that we have to strive to improve upon that in which we have already gained or been gifted with for a better term!  I'm curious about the code that you gave me bacause i do not fully understand how it works; i just know that it does and it works well!  If you do not mind;  when you get time;  could you comment it for me?  And if their are names for  certain parts of it;  please mention what they are.  Please understand that you have already done more than enough and more than i have found on other forums for me and i appreciate it deeply!  If you do not have the time;  please don't worry about it!  I understand!  I'm just trying to get this to click in my head so i can grow from it!  Thanks a lot for all your help and have a great and blessed day! 
________________________________________________________________________________________________________________________________
                                                                                       To live is *CHRIST*;   And to die is gain!

Re: PHP code script for adding wmv files

Dwayne -

PHP.net can be your friend. smile 

For instance, dir() will explain the syntax of the pseudo-class dir() followed by helpful submissions by programmers in how to use/augment what you're studying.

while is a loop control that will execute the contained statements as long as the condition resolves to a boolean TRUE.

$entry = $dir -> read() will read the next directory entry stored in the array $dir into the variable $entry.  Used as the while expression, will cause the script to loop through each array entry until all have been read.

strtolower makes sure all alpha characters present in the string are lowercase.

substr will present a portion of a string (the 1st parameter), starting at the 2nd parameter (in this case 0 - the 1st character), for the 3rd parameter number of characters (in this case the length of the string without the extension).

strlen simply presents the number of characters in a string.

Hopefully  this helps you understand a little more about what's going on here, and shows you where to learn more about other functions you encounter while studying other code snippets. smile

That's my 2 cents :^{>

Honored to Serve for Him - Tom ('Mas) Pickering <)><

Re: PHP code script for adding wmv files

Mas,  As always;  thanks once again my friend!  Thank you for taking the time to create the quick links to my php knowledge!  May *GOD* bless you for all your help and all your efforts you put forth helping those such as myself at the begining stages!   As I have experienced many in the past who would not go through the extra trouble you do!  Thats not aimed at anyone on this forum!  I have been on numerous forums that would insult the beginners!  I appreciate all of you guys on this site!
________________________________________________________________________________________________________________________________
                                                        The *WORD* to live by:  To live is *CHRIST*;  to die is gain!