function soundmap_ajax_file_uploaded_callback() { if (!isset($_FILES['Filedata'])) { die; } $rtn = array(); $rtn['error'] = ""; $file_data = $_FILES['Filedata']; if ($file_data['error'] != 0) { die; } $fileName = sanitize_file_name($file_data['name']); //Check the directory. $months_folders = get_option('uploads_use_yearmonth_folders'); $wud = wp_upload_dir(); if ($wud['error']) { $rtn['error'] = $wud['error']; echo json_encode($rtn); die; } $targetDir = $wud['path']; $targetURL = $wud['url']; //check if the file exists. if (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName)) { $ext = strrpos($fileName, '.'); $fileName_a = substr($fileName, 0, $ext); $fileName_b = substr($fileName, $ext); $count = 1; while (file_exists($targetDir . DIRECTORY_SEPARATOR . $fileName_a . '_' . $count . $fileName_b)) { $count++; } $fileName = $fileName_a . '_' . $count . $fileName_b; } $tempDir = $file_data['tmp_name']; //move it. $fileDir = $targetDir . DIRECTORY_SEPARATOR . $fileName; $fileURL = $targetURL . DIRECTORY_SEPARATOR . $fileName; if (!rename($tempDir, $fileDir)) { $rtn['error'] = __('Error moving the file.', 'soundmap'); echo json_encode($rtn); die; } $fileInfo = soundmap_get_id3info($fileDir); if (!($sound_attach_id = soundmap_add_media_attachment($fileDir, $fileURL))) { die; } $rtn['attachment'] = $sound_attach_id; $rtn['length'] = $fileInfo['play_time']; $rtn['fileName'] = $fileName; echo json_encode($rtn); die; }
function soundmap_rss_enclosure() { $id = get_the_ID(); $files = get_post_meta($id, 'soundmap_attachments_id', FALSE); foreach ((array) $files as $key => $value) { $fileURI = wp_get_attachment_url($value); $info = soundmap_get_id3info($file['filePath']); echo apply_filters('rss_enclosure', '<enclosure url="' . trim(htmlspecialchars($fileURI)) . '" length="' . trim($info['playtime_string']) . '" type="audio/mpeg" />' . "\n"); } }