【发布时间】:2015-09-12 20:41:06
【问题描述】:
我有一个上传视频的表单,视频的持续时间/长度很重要。
用PHP上传文件后,我用FFMpeg检查视频文件大小的持续时间。
我在 PHP 中计算持续时间,并且需要以某种方式通过 PHP 发送持续时间的值。我想我必须将持续时间附加到 Json 的 $result 变量中。
这是我的html
<!DOCTYPE html>
<html>
<head>
<script src=
"//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://rawgit.com/enyo/dropzone/master/dist/dropzone.js"></script>
<link href="css/dropzone.css" rel="stylesheet">
<script type="text/javascript">
Dropzone.options.myDropzone = {
maxFiles: 1,
acceptedFiles: "image/*,video/*",
maxfilesexceeded: function (file) {
this.removeAllFiles();
this.addFile(file);
$('#infomsg').hide();
},
init: function () {
$('#infomsg').hide();
this.on("success", function (result) {
$('#infomsg').show();
$("#boatAddForm").append($('<input type="hidden" ' +
'name="files[]" ' +
'value="' + result.name + '">'));
});
}
};
</script>
<title></title>
</head>
<body>
<p>
This is the most minimal example of Dropzone. The upload in this
example doesn't work, because there is no actual server to handle
the file upload.
</p><!-- Change /upload-target to your upload address -->
<form action="/dropzone/upload.php" class="dropzone" id="my-dropzone"
name="my-dropzone"></form>
<form action="/dropzone/son.php" id="boatAddForm" method="post" name=
"boatAddForm">
<input class="submit" type="submit">
</form>
</body>
</html>
这是我的 PHP
<?php
$ds = DIRECTORY_SEPARATOR;
$storeFolder = 'uploads';
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;
$targetFile = $targetPath. $_FILES['file']['name'];
move_uploaded_file($tempFile,$targetFile);
} else {
$result = array();
$files = scandir($storeFolder); //1
if ( false!==$files ) {
foreach ( $files as $file ) {
if ( '.'!=$file && '..'!=$file) { //2
$obj['name'] = $file;
$obj['size'] = filesize($storeFolder.$ds.$file);
$result[] = $obj;
}
}
}
header('Content-type: text/json'); //3
header('Content-type: application/json');
echo json_encode($result);
}
如果我可以在
之后立即检查自定义 json 响应 Dropzone.options.myDropzone = {
与成功的其他要求一样,我不必为了检查验证而对成功的 if 语句进行修正。
基本上我想按照我喜欢的方式去做
maxFiles: 1,
没有在里面写任何条件成功
【问题讨论】:
标签: javascript php jquery file-upload ffmpeg