Here's the original mp3 file: Pon-3jay LongR.mp3
And here's the corrupted version: pon-3jay longr.mp3

This is the script that moves the files over:

<?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 . '"}}';
}

?>

File.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:

<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>

This script is run on a CloudFlare host, just in case that changes anything. From what I noticed, all of the uploaded mp3 files upload as the same exact file. I honestly have no idea why this happens and how I could fix this. Any help is appreciated.

有帮助吗?

解决方案

The cover art (image) file is inadvertently saved instead of the mp3 file.

ref the following lines in 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
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top