我正在尝试创建一个代码来浏览PHP中的目录
#
# Command line use of 'ffprobe':
#
# ffprobe -loglevel quiet -print_format json \
# -show_format -show_streams \
# video-file-name.mp4
#
# man ffprobe # for more information about ffprobe
#
import subprocess32 as sp
import json
def probe(vid_file_path):
''' Give a json from ffprobe command line
@vid_file_path : The absolute (full) path of the video file, string.
'''
if type(vid_file_path) != str:
raise Exception('Gvie ffprobe a full file path of the video')
return
command = ["ffprobe",
"-loglevel", "quiet",
"-print_format", "json",
"-show_format",
"-show_streams",
vid_file_path
]
pipe = sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT)
out, err = pipe.communicate()
return json.loads(out)
def duration(vid_file_path):
''' Video's duration in seconds, return a float number
'''
_json = probe(vid_file_path)
if 'format' in _json:
if 'duration' in _json['format']:
return float(_json['format']['duration'])
if 'streams' in _json:
# commonly stream 0 is the video
for s in _json['streams']:
if 'duration' in s:
return float(s['duration'])
# if everything didn't happen,
# we got here because no single 'return' in the above happen.
raise Exception('I found no duration')
#return None
if __name__ == "__main__":
video_file_path = "/tmp/tt1.mp4"
duration(video_file_path) # 10.008
$ scan和$ scanner变量是进入下拉列表以选择下一个文件夹的数组。但是我的代码只能工作两次。
示例:
我们从文件夹开始。
然后下拉列表显示nextfolder
我们现在位于文件夹/ nextfolder。
我们再次选择任何文件夹。
程序转到文件夹/ anyfolder而不是folder / nextfolder / anyfolder。
有什么想法吗?我想我应该继续以某种方式保存当前目录。但我不知道该怎么做。
答案 0 :(得分:0)
你需要使用递归函数来做到这一点。
function navigate($path){
static $scanned = array();
$dir = scandir($path,1);
foreach ($dir as $obj) {
if(strlen($obj) > 2){
if(is_dir($path.$obj)){
//directory
$scanned = indir($path.$obj.'/');
} else {
//file
}
}
}
return $scanned;
}