0

元の mp3 ファイルは次のとおりです: Pon-3jay LongR.mp3
そして、これが破損したバージョンです: pon-3jay longr.mp3

これは、ファイルを移動するスクリプトです。

<?php

require_once "File.php";
$path = "uploads/songs/";
$valid_formats = array("mp3");
$File = new File();

$path = $path."djdavid98/";

    if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
        $name = $_FILES['song']['name'];
        $size = $_FILES['song']['size'];
        $tmp  = $_FILES['song']['tmp_name'];

        if (!is_dir($path)) mkdir($path, 0777, true);

        if($File->upload($tmp, $actual_song_name,$path)){
            echo response($path.$actual_song_name,$actual_song_name,$txt.".".$ext);
        }
        else echo errText("Upload failed!", $path );
    }

function errText($str,$fileName){
    return '{"song":{"sucess":"0","message":"' .$str. '","fileName":"' . $fileName . '"}}';
}
function response($filePath,$actualFileName,$fileName){
    return '{"song":{"sucess":"1","path":"' . $filePath . '","fileName":"' . $fileName . '"}}';
}

?>

ファイル.php:

<?php
    class File {
        public function upload($file, $filename, $target_path) {
            if (empty($filename)) { break; }
            try {
                $target_path = $target_path . $filename;

                if(move_uploaded_file($file, $target_path)) {
                    return true;
                } else{
                    return false;
                }
            } catch (Exception $ex) {
                echo "Error on <strong>Line " . $ex->getLine() . " </strong>: " . $ex->getMessage();
            }
        }
    }
?>

形:

<form class="upload_form" enctype="multipart/form-data" style="height:0;opacity:0;">
    <div class="grid-100 grid-parent">
        <div class="grid-20">
            ...
            <div data-input>
                <span>Song</span>
                <div class="grid-100 grid-parent fileSelect">
                    <div class="grid-60">
                        <input type="text" disabled class="file-holder">
                    </div>
                    <div class="file-wrapper grid-40">
                        <input type="file" name="song" required>
                        <div class="button styleWarning">Browse</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="grid-80 grid-parent">
            ...
        </div>
    </div>
</form>

このスクリプトは、何かが変更された場合に備えて、CloudFlare ホストで実行されます。私が気づいたことから、アップロードされたすべての mp3 ファイルはまったく同じファイルとしてアップロードされます。正直なところ、なぜこれが起こるのか、どうすればこれを修正できるのかわかりません。どんな助けでも大歓迎です。

4

1 に答える 1