예제 #1
0
function get_mp3duration($attachment)
{
    require_once VIVVO_FS_INSTALL_ROOT . 'lib/zedwood/mp3file.php';
    $mp3 = new mp3file($filename = VIVVO_FS_ROOT . VIVVO_FS_FILES_DIR . $attachment->real_path);
    $metadata = $mp3->get_metadata();
    if (isset($metadata['Length'])) {
        return $metadata['Length'];
    } else {
        return ceil(filesize($filename) / 60000000);
        // 128kbps, stereo
    }
}
예제 #2
0
    if (!($voiceshadow = $DB->get_record("voiceshadow", array("id" => $a)))) {
        error("Course module is incorrect");
    }
    if (!($course = $DB->get_record("course", array("id" => $voiceshadow->course)))) {
        error("Course is misconfigured");
    }
    if (!($cm = get_coursemodule_from_instance("voiceshadow", $voiceshadow->id, $course->id))) {
        error("Course Module ID was incorrect");
    }
}
$name = "var{$var}";
$linktofile = $CFG->wwwroot . '/mod/voiceshadow/file.php?file=' . $voiceshadow->{$name};
$file = voiceshadow_getfileid($voiceshadow->{$name});
$AF = new AudioFile();
if (is_file($file->fullpatch)) {
    $AF->loadFile($file->fullpatch);
    $duration = round($AF->wave_length);
    if (empty($duration)) {
        $m = new mp3file($file->fullpatch);
        $a = $m->get_metadata();
        $duration = $a['Length'];
    }
}
if ($uid) {
    $USER = $DB->get_record("user", array("id" => $uid));
}
if (empty($time)) {
    $time = time();
}
$json = array("play" => $linktofile, "title" => $voiceshadow->name, "descr" => strip_tags($voiceshadow->intro), "type" => 'voiceshadow', "id" => $id, "cid" => $course->id, "uid" => $USER->id, "filename" => str_replace(" ", "_", $USER->username) . "_" . date("Ymd_Hi", $time), "duration" => $duration);
echo json_encode($json);
         // if directory doesn't exist attempt to create it
         if (!file_exists(UPLOAD_DIR)) {
             mkdir(UPLOAD_DIR, 0700);
         }
         //stores the file location...relative directory
         $fileLocation = UPLOAD_DIR . $name;
         print_r($fileLocation);
         // try to move the file to the proper directory
         $success = move_uploaded_file($audioFile["tmp_name"], $fileLocation);
         // if unsucessful print error and exit
         if (!$success) {
             echo "<p> unable to save file. </p>";
             exit;
         } else {
             $mp3Info = new mp3file($fileLocation);
             $mp3Data = $mp3Info->get_metadata();
             $mp3Duration = $mp3Info->getDuration($mp3Data, 0);
             $length = $mp3Data['Length mm:ss'];
             // set permissions on the new file
             chmod(UPLOAD_DIR . $name, 0644);
             // add user's audio to db
             $query = 'CALL audio_add("' . $audio_name . '","' . $extension . '","' . $bitrate . '","' . $tempo . '","' . $size . '","' . $length . '","' . $genre . '","' . $price . '","' . $member_id . '"' . ')';
             $result = $db->query($query);
         }
     }
     // no error found
 } else {
     $error_flag++;
     echo "<p> Wrong file </p>";
     echo $_FILES["audiofile"]["error"] . " " . $_FILES["audiofile"]["type"];
 }