Created
February 12, 2019 13:01
-
-
Save ugeugeHigh/2d9bb02dbbf8cb7722c5bf8e0bcf2eb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$file = $_FILES['gif']; | |
//var_dump($file); | |
$ext = substr($file['name'], -4); //ファイル名の後ろ4文字を取得。つまり拡張子を取り出す | |
if($ext == '.MOV' || $ext == '.mov' || $ext == '.mp4') { | |
$filePath = 'tmp/' . $file['name']; //ファイルの移動先。 | |
move_uploaded_file($file['tmp_name'], $filePath);//アップロード | |
$gifname = makeName(); | |
exec('ffmpeg -i ' .$filePath. ' tmp/' .$gifname); | |
print('<img src="tmp/'.$gifname.'">');//アップロードした写真を表示する | |
//アップロードしたファイルを削除 | |
unlink($filePath); | |
}else { | |
print('error'); | |
} | |
function makeName() { | |
date_default_timezone_set('UTC'); | |
//$fileName = date("Y-m-d-H-I-s"); | |
$fileName = date("Y-m-d"); | |
$tmp = $fileName; | |
$i = 0; | |
while(file_exists('tmp/' . $tmp . '.gif')){ | |
$tmp = $fileName . '_' . $i; | |
$i++; | |
if($i>100){ | |
break; | |
} | |
} | |
return $tmp . '.gif'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment