function processFileUpload() { $target_path = $GLOBALS['upload_path']; $target_path = $target_path . basename($_FILES['audioFile']['name']); if (move_uploaded_file($_FILES['audioFile']['tmp_name'], $target_path)) { $addMusic = new addMusic(); if ($_POST['upload_structured'] == "true") { $addMusic->getID3Data($target_path, $goodData); $final_path = $GLOBALS['upload_path'] . $goodData['artist'] . "/" . $goodData['album']; // need some logic to handle illegal filesystem characters before you do this. //$final_file_name = $goodData['artist'] . "-" . $goodData['album'] . "-" . $goodData['track'] . "-" . $goodData['name']; // for now just keep the filename the same $final_file_name = basename($_FILES['audioFile']['name']); $final_path_file_name = $final_path . "/" . $final_file_name; mkdir($final_path, 0777, true); rename($target_path, $final_path_file_name); $addMusic->setPath($final_path); $addMusic->setFileList($final_path, "/" . $final_file_name, $songs); } else { $addMusic->setPath($GLOBALS['upload_path']); $addMusic->setFileList($GLOBALS['upload_path'], basename($_FILES['audioFile']['name']), $songs); // removed as this tries to update every thing in the directory. //$addMusic->getSongs($GLOBALS['upload_path'],$songs); } $songsAdded = $addMusic->insertSongs(); if ($songsAdded > 0) { return true; } } return false; }
<div id="header"> <h1>mp3act Add Music</h1> Enter a music directory on the server or upload a file. </div> <p id="error" class='pad'></p> <?php if (isset($_GET['add']) && $_GET['add'] == 1 && isset($_GET['musicpath'])) { $path = $_GET['musicpath']; if ($path[strlen($path) - 1] != '/') { $path .= "/"; } session_write_close(); // otherwise progress isn't shown! echo "<div class='box'><div class=\"head\"><h2>Import results</h2></div><ul>"; $addMusic = new addMusic(); $addMusic->setPath($path); $addMusic->getSongs($path, $songs, $errors); $songsAdded = $addMusic->insertSongs(); echo "<li>Added <strong>{$songsAdded} Songs</strong> To The Database</li>"; echo "</ul></div>"; } elseif (isset($_FILES['musicfile']['name'])) { echo "<pre>"; print_r($_FILES); echo "</pre>"; echo $_FILES['musicfile']['tmp_name']; echo "<br/>" . $_FILES['musicfile']['name']; move_uploaded_file($_FILES['musicfile']['tmp_name'], $GLOBALS[upload_path] . "/" . $_FILES['musicfile']['name']); } else { echo "<form action='add.php' method='get' onsubmit='return validator()'>\n"; echo "<p class='pad'><input type='hidden' value=1 name='add' /><input type='text' onfocus='this.select()' name='musicpath' id='musicpath' size='45' id='musicpath' value='/path/to/music' /><br/><br/>"; echo "<input type='submit' value='add music' class='btn' /><br/><br/>Be Patient While Music is Added. It could take several minutes.</p>";
} else { // do the import.. set_time_limit(0); // no time limit, this can take a while eh! session_write_close(); // otherwise progress isn't shown! echo "<div class='box'><div class=\"head\"><h2>Import results</h2></div><ul>"; $addMusic = new addMusic(); /* start by doing directories. progress per directory. */ if (count($queuedirs) > 0) { foreach ($queuedirs as $importdir) { echo "<li>Importing directory {$importdir}</li>"; if ($path[strlen($importdir) - 1] != '/') { $importdir .= "/"; } $addMusic->setPath($importdir); unset($songs); $addMusic->getSongs($importdir, $songs); $songsAdded = $addMusic->insertSongs(); echo "<li>Added <strong>{$songsAdded} Songs</strong> To The Database</li>"; } } /* then do files. here we can have one progress bar for all! */ if (count($queuefiles) > 0) { echo "<li>Adding separate songs to the database</li>"; mp3act_connect(); $last_timestamp = 0; $getID3 = new getID3(); $songsAdded = 0; $num_files = count($queuefiles); foreach ($queuefiles as $importfile) {