Created
August 16, 2019 15:32
-
-
Save gollilla/154dd63a6d7f21430996adc796d0659d 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 | |
require './vendor/autoload.php'; | |
use Ramsey\Uuid\Uuid; | |
const WORKING_SPACE_DIR = "./music_working_space/"; | |
var_dump($_FILES); | |
if(isset( $_FILES['input_file'] )){ | |
$i=0; | |
foreach( $_FILES['input_file']["tmp_name"] as $tmp ){ | |
if( is_uploaded_file($tmp) ){ | |
$local_name = ((string) rand(100000, 999999)); | |
$local_name .= ".ogg"; | |
$music_file = WORKING_SPACE_DIR . $local_name; | |
$music_files[] = $music_file; | |
$music_names[] = pathinfo( $_FILES['input_file']['name'][$i++] )['filename']; | |
move_uploaded_file( $tmp, $music_file ); | |
} | |
} | |
$manifest_json = [ | |
"format_version" => 1, | |
"header" => [ | |
"name" => "MusicResourcePack", | |
"description" => "MusicResourcePack", | |
"uuid" => Uuid::uuid4()->toString(), | |
"version" => [ | |
1,0,0 | |
] | |
], | |
"modules" => [ | |
"description" => "MusicResourcePack", | |
"uuid" => Uuid::uuid4()->toString(), | |
"version" => [ | |
1,0,0 | |
] | |
] | |
]; | |
foreach($music_names as $name){ | |
$sound_json[] = [ | |
"music." . $name => [ | |
"sounds" => [ | |
"volume" => 1, | |
"name" => "sounds/music/" . $name | |
], | |
"category" => "music" | |
] | |
]; | |
} | |
$manifest_path = WORKING_SPACE_DIR . ((string) rand(100000, 999999)); | |
$manifest_path .= ".json"; | |
$sound_path = WORKING_SPACE_DIR . ((string) rand(100000, 999999)); | |
$sound_path .= ".json"; | |
$manifest_json = json_encode( $manifest_json ); | |
$sound_json = json_encode( $sound_json ); | |
file_put_contents( $manifest_path, $manifest_json ); | |
file_put_contents( $sound_path, $sound_json ); | |
$zip = new ZipArchive; | |
$zip_name = uniqid( rand() ) . '.zip'; | |
$zip_path = WORKING_SPACE_DIR . $zip_name; | |
$zip->open( $zip_path, ZipArchive::CREATE|ZipArchive::OVERWRITE ); | |
$zip->addFile( $manifest_path, "manifest.json" ); | |
$zip->addEmptyDir("sounds/music"); | |
$zip->addFile( $sound_path, "sounds/sound_definitions.json" ); | |
$i=0; | |
foreach( $music_files as $music){ | |
$zip->addFile( $music, "sounds/music/" . $music_names[$i++] . ".ogg" ); | |
} | |
$zip->close(); | |
rename( $zip_path, $zip_path . ".mcpack"); | |
header('Content-Type: application/force-download'); | |
header('Content-Length: '.filesize( $zip_path . ".mcpack" )); | |
header('Content-Disposition: attachment; filename="'. $zip_name . ".mcpack" .'"'); | |
mb_http_output("pass"); | |
readfile($zip_path . ".mcpack"); | |
}else{ | |
echo "<html>"; | |
echo "<body>"; | |
echo "<form action='./index.php' method='post' enctype='multipart/form-data' >"; | |
echo "<input type='file' name='input_file[]'>"; | |
echo "<input type='submit' value='送信' >"; | |
echo "</form>"; | |
echo "</body>"; | |
echo "</html>"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment