我正在使用cordova文件传输插件将视频上传到我的网络服务器。下面是前端的代码。
var uri = encodeURI("https://www.abc.xyz/app/upload_vid.php");
fileURL = "file://"+filefromgallery;
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=fileURL.substr(fileURL.lastIndexOf('/')+1);
options.mimeType="video/mp4";
options.chunkedMode = false;
options.headers = {
Connection: "close"
};
var ft = new FileTransfer();
ft.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
} else {
loadingStatus.increment();
}
};
ft.upload(fileURL, uri, win, fail, options);
}
这是后端代码。
$dirname = "./video";
$filename = 'test';
if ($_FILES) {
print_r($_FILES);
move_uploaded_file($_FILES["name"]["tmp_name"],$dirname."/".$filename.'.mp4');
}
我今天做了一些调试。
这是print_r($_FILES);
Response = Array
(
[file] => Array
(
[name] => video-name-here.mp4
[type] => video/mp4
[tmp_name] => /tmp/phpJzw3UB
[error] => 0
[size] => 479000
)
)
<b>Notice</b>: Undefined index: name in <b>/home/u966130057/public_html/model_app/upload_vid.php</b> on line <b>18</b><br />
In Console debug i am getting below error for frontend.
Uncaught ReferenceError: loadingStatus is not defined
at FileTransfer.ft.onprogress (index.js:214)
at win (FileTransfer.js:159)
at Object.callbackFromNative (cordova.js:293)
at <anonymous>:1:283