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

1

无意中保存了封面艺术(图像)文件而不是 mp3 文件。

参考 ajaxprocessform.php 中的以下行:

$tmp = $_FILES['cover']['tmp_name']; //this is the image

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

if($File->upload($tmp, $actual_song_name,$path)){ //image saved with mp3 path
于 2013-04-24T20:01:48.100 回答