|
@@ -788,3 +788,98 @@ function createUniqueNo($prifix = 'P',$id = 0)
|
|
|
|
|
|
return $rt;
|
|
|
}
|
|
|
+
|
|
|
+//下载远程图片 到指定目录
|
|
|
+function downloadfile($file_url, $path = '', $save_file_name = '')
|
|
|
+{
|
|
|
+ $basepath = '/uploaded/';
|
|
|
+ if ($path) {
|
|
|
+ $basepath = $basepath . $path . '/';
|
|
|
+ }
|
|
|
+ $basepath = $basepath . date('Ymd');
|
|
|
+ $dir_path = ROOT_PATH . '/public' . $basepath;
|
|
|
+ if (!is_dir($dir_path)) {
|
|
|
+ mkdir($dir_path, 0777, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ $ch = curl_init();
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $file_url);
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+
|
|
|
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
|
|
|
+
|
|
|
+ $file = curl_exec($ch);
|
|
|
+
|
|
|
+ curl_close($ch);
|
|
|
+
|
|
|
+ //传入保存文件的名称
|
|
|
+ $filename = $save_file_name ?: pathinfo($file_url, PATHINFO_BASENAME);
|
|
|
+
|
|
|
+ $resource = fopen($dir_path. '/'. $filename, 'a');
|
|
|
+
|
|
|
+ fwrite($resource, $file);
|
|
|
+
|
|
|
+ fclose($resource);
|
|
|
+
|
|
|
+ return $dir_path . '/' . $filename;
|
|
|
+}
|
|
|
+
|
|
|
+//获取视频时长
|
|
|
+function get_video_seconds($netpath = ''){
|
|
|
+
|
|
|
+ $local_url = downloadfile($netpath,'video','');
|
|
|
+ $playtime = 0;
|
|
|
+
|
|
|
+ Vendor('getid3.getid3.getid3');
|
|
|
+ $getID3 = new \getID3();
|
|
|
+ $fileinfo = $getID3->analyze($local_url);
|
|
|
+
|
|
|
+ if(isset($fileinfo['playtime_seconds'])){
|
|
|
+ $playtime = (int)$fileinfo['playtime_seconds'];
|
|
|
+ }
|
|
|
+
|
|
|
+ return $playtime;
|
|
|
+}
|
|
|
+
|
|
|
+//post接收参数中心,只接非必须
|
|
|
+function request_post_hub($field_array = [],$required = [],$noempty = []){
|
|
|
+ if(empty($field_array)){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+
|
|
|
+ foreach($field_array as $key => $field){
|
|
|
+
|
|
|
+ //接收
|
|
|
+ if(!request()->has($field,'post')){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ $newone = request()->post($field);
|
|
|
+
|
|
|
+ //追加
|
|
|
+ $data[$field] = $newone;
|
|
|
+ }
|
|
|
+
|
|
|
+ //必传
|
|
|
+ if(!empty($required)){
|
|
|
+ foreach($required as $k => $mustone){
|
|
|
+ if(!isset($data[$mustone])){
|
|
|
+ return $mustone.' required';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //必传,且不能空
|
|
|
+ if(!empty($noempty)){
|
|
|
+ foreach($noempty as $havekey => $haveone){
|
|
|
+ if(!isset($data[$havekey]) || empty($data[$havekey])){
|
|
|
+ return $haveone.' 必填';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+}
|