gpt4 book ai didi

javascript - PhoneGap 文件传输在上传到服务器时损坏 .mp3

转载 作者:行者123 更新时间:2023-11-30 18:02:44 25 4
gpt4 key购买 nike

我正在为一个项目弄乱 PhoneGap,但我在上传 .mp3 时遇到了一些问题

我能够使用设备的内置麦克风录制 mp3,然后我能够使用以下 JavaScript 上传文件:

var audio_name = 'fyp_app_recording_' + Math.round(new Date().getTime()/1000) + '.mp3';

// Record audio
//
function recordAudio() {

var src = audio_name;
var mediaRec = new Media(src, onSuccess(src), onError);

// Record audio
mediaRec.startRecord();

// Stop recording after 10 sec
var recTime = 0;
var recInterval = setInterval(function() {
recTime = recTime + 1;
setAudioPosition("Recording Audio - " + recTime + " sec");
if (recTime >= 10) {
clearInterval(recInterval);
mediaRec.stopRecord();
setAudioPosition("Recording Saved As " + src);
}
}, 1000);
}

// onSuccess Callback
//
function onSuccess(src) {
console.log("recordAudio():Audio Success" + src);
}

// onError Callback
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}

// Set audio position
//
function setAudioPosition(position) {
document.getElementById('audio_position').innerHTML = position;
}

//File upload

function uploadAudio() {

var options = new FileUploadOptions();
options.fileKey="file";
options.fileName="test.mp3";
options.mimeType="audio/mpeg";

var ft = new FileTransfer();
ft.upload("mnt/sdcard/" + audio_name, "http://www.richardsonweb.co.uk/fyp/test1/upload.php", win, fail, options);
}

function win() {
alert("Yay! It worked!");
}

function 7(error) {
alert("An error has occurred: Code = " = error.code);
}

upload.php 文件包含以下代码:

    print_r($_FILES);



$new_file_name = time() . ".mp3";
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/".$new_file_name);

但是,当我从我的 FTP 客户端下载文件时,Windows Media Player 声称文件已损坏。

奇怪的是,该文件在 VLC 中播放得很好(进度条在 10 秒时卡住了,并且没有移动,但它完美地播放了音频)。

知道为什么会发生这种情况吗?提前致谢!

最佳答案

尝试使用这个 php 代码

<?php
$destination_path = getcwd().DIRECTORY_SEPARATOR;

$result = 0;

$target_path = $destination_path . time() . ".mp3";

ini_set("upload_max_filesize", "3200000000");

if(@move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
$result = 1;
}

sleep(1);
?>

关于javascript - PhoneGap 文件传输在上传到服务器时损坏 .mp3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16523858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com