Created
February 22, 2019 01:37
-
-
Save ugeugeHigh/ef9e5399dd0d8d98cf124e32670541d4 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']; | |
$frameRate = $_POST['frameRate']; | |
//var_dump($file); | |
$ext = substr($file['name'], -4); //ファイル名の後ろ4文字を取得。つまり拡張子を取り出す | |
if(is_uploaded_file($file['tmp_name'])){ | |
if($ext == '.MOV' || $ext == '.mov' || $ext == '.mp4') { | |
$filePath = 'tmp/' . $file['name']; //ファイルの移動先。 | |
move_uploaded_file($file['tmp_name'], $filePath);//アップロード | |
$gifname = makeName(); | |
exec('ffmpeg -i ' .$filePath.' -r '. $frameRate. ' tmp/' .$gifname); | |
//print('<img src="tmp/'.$gifname.'">');//アップロードした写真を表示する | |
//アップロードしたファイルを削除 | |
unlink($filePath); | |
//gifファイルをダウンロード | |
header('Content-Type: application/force-download'); | |
header('Content-Length: '.filesize('tmp/' .$gifname)); | |
header('Content-disposition: attachment; filename="'.$gifname.'"'); | |
readfile('tmp/' .$gifname); | |
//gifファイルをtmp/から削除 | |
unlink('tmp/'.$gifname); | |
//選択画面に戻る | |
header('Location: gifhome.php'); | |
}else { | |
header('Location: gifhome.php'); | |
} | |
} else { | |
header('Location: gifhome.php'); | |
} | |
function makeName() { | |
date_default_timezone_set('UTC'); | |
$fileName = date("Y-m-d-H-I-s"); | |
$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