Question: The sample code provided is a Song Organizer script that stores songs in a text file. Include functionality that allows users to view the song
The sample code provided is a Song Organizer script that stores songs in a text file. Include functionality that allows users to view the song list and prevents the same song name from being entered twice. Also, included is code that will sorts the songs by name, deletes duplicate entries, and randomizes the song list with the shuffle() function.
Add detailed comments into the code ( // Comment or /* Comment */) explaining how the code works. Specifically, add comments to the code where comments are required.
Note: Please type up the whole PHP file, add in your comments and save the file as SongOrganizer.php. Upload SongOrganizer.php to the class web server in your module7a directory for grading.
Note: Code should work on your local computer. A file permission change is required on the server to get it to work correctly on the class server.



2 3 4 5
Song Organizer
0) { $NewSongs = implode($SongArray); $SongStore = fopen("SongOrganizer/songs.txt", "wb"); if ($SongStore === false) echo "There was an error updating the song file "; else { fvrite($SongStore, $NewSongs); fclose($SongStore); 36 37 38 39 40 41 } else unlink ("SongOrganizer/songs.txt"); 42 43 44 46 47 //Comment: Explain line 47 if (isset($_POST['submit'])) { $SongToAdd = stripslashes ($_POST['SongName']) . " "; $ExistingSongs = array(); 48 49 50 51 52 53 //Comment: Explain line 51 - 69 if (file_exists("SongOrganizer/songs.txt") 66 filesize("SongOrganizer/songs.txt") > 0) { $ExistingSongs = file("SongOrganizer/songs.txt"); 54 55 56 57 58 59 60 if (in_array($SongToAdd, $ExistingSongs)) { echo "
The song you entered already exists!
"; echo "Your song was not added to the list.
"; } else { $SongFile = fopen("SongOrganizer/songs.txt", "ab"); if ($SongFile === false) echo "There was an error saving your message! "; else { fvrite($SongFile, $Song ToAdd); fclose($SongFile); echo "Your song has been added to the list. "; 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 1/Comment: Explain line 73 - 84 if ((!file_exists("SongOrganizer/songs.txt")) 11 (filesize("SongOrganizer/songs.txt") == 0)) echo "
There are no songs in the list.
"; else { $SongArray = file("SongOrganizer/songs.txt"); echo "
| " . htmlentities ($Song) . " | "; echo '
"; } 79 80 81 82 83 85 86 ?> 88 89
Sort Song List
Remove Duplicate Songs
Randomize Song list
91 92 93 94 95 96 F
97 98 99 100 101 102 103 104
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
