JavaScript appears to be disabled. We recommend you enable JavaScript while visiting this site.

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

iTunes Track class in C# and PHP

I've recently begun reading up on PHP again. As I'm most fond of my iTunes Playlists to Xml application, I thought I'd work with that application's output - XML files with playlist data - as I continued to dig into PHP (instead of stopping now that I know enough to tweak existing code and create new functionality).

Here's a basic Track object in C# and PHP. I'll of course be elaborating on these as time goes by (and already have code for the C# implementation).

Track class in C#

/// <summary>
/// Music track object.
/// </summary>
public class Track {
	#region Properties
	/// <summary>
	/// How long the track is.
	/// </summary>
	public String Time { get; set; }
	/// <summary>
	/// Name or title of the track.
	/// </summary>
	public String Name { get; set; }
	/// <summary>
	/// Name of the artist.
	/// </summary>
	public String Artist { get; set; }
	/// <summary>
	/// Rating assigned to the track by the playlist's owner.
	/// </summary>
	public int Rating { get; set; }
	/// <summary>
	/// Number of times the track has been played.
	/// </summary>
	public int PlayCount { get; set; }
	/// <summary>
	/// Date and time the track was last played (and finished).
	/// </summary>
	public DateTime LastPlayed { get; set; }
	/// <summary>
	/// Name of the album the track is from.
	/// </summary>
	public String Album { get; set; }
	/// <summary>
	/// True if the album the track is on is a compilation, false otherwise.
	/// </summary>
	public Boolean Compilation { get; set; }
	/// <summary>
	/// Order this track is on the album.
	/// </summary>
	public int TrackNumber { get; set; }
	/// <summary>
	/// Total number of tracks on the album.
	/// </summary>
	public int TrackCount { get; set; }
	/// <summary>
	/// The album disc the track is on.
	/// </summary>
	public int DiscNumber { get; set; }
	/// <summary>
	/// Total number of discs in the album.
	/// </summary>
	public int DiscCount { get; set; }
	/// <summary>
	/// Year the track/album was released/published.
	/// </summary>
	public int Year { get; set; }
	/// <summary>
	/// Genre of music the track falls into.
	/// </summary>
	public String Genre { get; set; }
	/// <summary>
	/// Date and time the track was added.
	/// </summary>
	public DateTime DateAdded { get; set; }
	#endregion
}

Track class in PHP

<?php
/**
 * Music track object.
 *
 * @author James Skemp
 */
class Track {
	/**
	 * How long the track is.
	 * @var string
	 */
	var $Time;
	/**
	 * Name or title of the track.
	 * @var string
	 */
	var $Name;
	/**
	 * Name of the artist.
	 * @var string
	 */
	var $Artist;
	/**
	 * Rating assigned to the track by the playlist's owner.
	 * @var int
	 */
	var $Rating;
	/**
	 * Number of times the track has been played.
	 * @var int
	 */
	var $PlayCount;
	/**
	 * Date and time the track was last played (and finished).
	 */
	var $LastPlayed;
	/**
	 * Name of the album the track is from.
	 * @var string
	 */
	var $Album;
	/**
	 * True if the album the track is on is a compilation, false otherwise.
	 * @var bool
	 */
	var $Compilation;
	/**
	 * Order this track is on the album.
	 * @var int
	 */
	var $TrackNumber;
	/**
	 * Total number of tracks on the album.
	 * @var int
	 */
	var $TrackCount;
	/**
	 * The album disc the track is on.
	 * @var int
	 */
	var $DiscNumber;
	/**
	 * Total number of discs in the album.
	 * @var int
	 */
	var $DiscCount;
	/**
	 * Year the track/album was released/published.
	 * @var int
	 */
	var $Year;
	/**
	 * Genre of music the track falls into.
	 * @var string
	 */
	var $Genre;
	/**
	 * Date and time the track was added.
	 */
	var $DateAdded;
	
    //todo
}
?>

Comments appreciated.

Tags: ,

Categories: article

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Enabling PHP file_put_contents() support on IIS 7.5 on Windows Server 2008 R2

I've already installed the current verison of PHP 5.2 on my Windows Server 2008 R2 machine, but unfortunately wasn't able to get content saved via the file_put_contents function.

It seems that you need to add and give IUSR the necessary permissions on the file (or directory) in order for writes to work properly.

Tags: , ,

Categories: software

(All original content on this site is licensed under the Creative Commons License Attribution-Noncommercial-No Derivative Works 3.0.)

Upgrading PHP (4.4.2 to 4.4.4 and 5.1.4 to 5.2.0)

In this article, we'll be upgrading PHP on our local, Windows, Web server. In previous guides we installed PHP 4.4.2 as well as PHP 5.1.4, both on the same machine, with the ability to switch as we like. However, we've yet to cover how to upgrade either installation (and upgrading is definitely a need).

At the time of this writing, the current versions of PHP are 4.4.4 and 5.2.0, for the 4.x and 5.x versions, respectively.

We'll be going over the upgrade for each version separately, so you can simply skip to which version you're currently using.

Upgrading PHP 4.4.2 to PHP 4.4.4

First off, make sure that Apache has been stopped.

Now, rename the directory where you've installed PHP 4.x to ... have the suffix of '-previous' (for example, c:\php4-previous\). We'll do this, instead of installing over the directory so that we have a backup copy, as well as a 'clean' version of the install directory.

Next, you should have, or should, download the Windows binary in zip format, for the most current version of PHP 4.x (4.4.4 at the time of this writing). Extract the contents of this folder so that you have the same directory structure as before.

For example, for the previous version of PHP, my php.exe file was at c:\php4\php.exe. For the new install, I'll want php.exe to be in the same location.

Once that's done, we'll want to grab the php4apache.dll and/or php4apache2.dll files from our previous install directory and put a copy of them into our new install directory.

For the new version of PHP 4.x, make a copy the php4ts.dll file and put the copy in the Windows folder (c:\windows\).

Next, there's the matter of the php.ini file. At this point, I did a compare of the new version's file with the previous version's file (php.ini-dist) using WinMerge. Luckily, the two files are identical, so there's no updating necessary.

At this point, you can start up Apache and hit your phpinfo page (code listed below). You should see that PHP's version has been updated to 4.4.4. If you'd like, you can also test your connection to the database server of your choice (MySQL and/or PostgreSQL).

<?php
phpinfo();
?>

Now that we're set with our new version of PHP 4.x, you can either delete, or as I recommend, archive, your old PHP install directory, just in case something comes up in the next couple of weeks. Also, if you have any non-core extensions, you'll want to make sure that those get moved over as well.

Next, we've got our PHP 5.x installation to upgrade.

Upgrading PHP 5.1.4 to PHP 5.2.0

Upgrading PHP 5.x is almost exactly the same as upgrading PHP 4.x.

First, make sure that Apache has been stopped. Next, rename your current PHP 5.x directory (I added '-previous' to the end of my directory's name). If you don't already have a copy, download the Windows PHP 5.x binaries and extract them so that you preserve the same file structure as before.

For example, php.exe was located at c:\php5\php.exe for my previous version, so that's also where it should sit in the new directory.

Next, make a copy of the php5ts.dll file and put it into the Windows directory (c:\windows\ for example), overwriting the old one. If you installed any extensions, copy those extensions over from your previous install's directory to your new install's directory.

Now there's the matter of the php.ini file. At this point, I did a compare of the new version's file with the previous version's file (php.ini-dist) using WinMerge and there's a number of changes.

So, what you'll want to do is compare your PHP.ini file with the php.ini-dist file from the previous version, so we can get an idea of what changes were made. Now, make a copy of the new php.ini-dist and make the same changes you've made for the old version.

For example, six changes had been made to my php.ini file, which I've listed below.

doc_root
extension_dir
extension=php_mysql.dll
extension=php_pgsql.dll
session.save_path
[Zend]

Once you've ported over all of your changes, make a backup of your old php.ini file and replace it with the updated version. You can now restart Apache (2) and verify using phpinfo() that your version has been upgraded. You'll also want to check your database connection(s) as well.

And with that, you've updated PHP 5.x.

View all of the steps to creating a local Web server, for development.

Tags: ,

Categories: tutorials/guides