コード例 #1
0
ファイル: sync.php プロジェクト: benbruscella/Gramophone
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;
}