三种文件类型保存为一个?

时间:2015-12-16 19:14:57

标签: php file types upload web

您好我有一个网站可以上传三种类型的文件,但是当我上传时,无论上传哪种类型,它们都会变成.aiff文件。 Suuuper跛脚。我在哪里出错这个代码? :/ 非常感谢。 (其中一些代码是由另一个人制作并修改的)

// Types of files that are acceptiable for uploading. Keep the array structure.
$allow_types=array("wav","mp3","aiff");

// Function to get the extension a file.
function get_ext($key) { 
    $key=strtolower(substr(strrchr($key, "."), 1));
    $key=str_replace("wav","mp3","aiff",$key);
    return $key;
}

    //Tally the size of all the files uploaded, check if it's over the ammount. 
    If(array_sum($_FILES['file']['size']) > $max_combined_size*1024) {

        $error.="<b>FAILED:</b> All Files <b>REASON:</b> Combined file size is to large.<br />";

    // Loop though, verify and upload files.
    } Else {
print $key; 
        // Loop through all the files.
        For($i=0; $i <= $file_uploads-1; $i++) {

            // If a file actually exists in this key
            If($_FILES['file']['name'][$i]) {

                //Get the file extension
                $file_ext[$i]=get_ext($_FILES['file']['name'][$i]);

                // Randomize file names
                If($unique_name){

                if($key=1){
                $file_name[$i]=1;
                while(1){
                $file_name[$i] =$file_name[$i]+1;
                if (!file_exists("uploads/$file_name[$i].aiff")){ break;}
                }}

                elseif($key=2){
                $file_name[$i]=1;
                while(1){
                $file_name[$i] =$file_name[$i]+1;
                if (!file_exists("uploads/$file_name[$i].mp3")){ break;}
                }}
                elseif($key=3){
                $file_name[$i]=1;
                while(1){
                $file_name[$i] =$file_name[$i]+1;
                if (!file_exists("uploads/$file_name[$i].wav")){ break;}
                }}

                } Else {
                    $file_name[$i]=cln_file_name($_FILES['file']['name'][$i]);
                }

                // Check for blank file name
                If(str_replace(" ", "", $file_name[$i])=="") {

                    $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Blank file name detected.<br />";

                //Check if the file type uploaded is a valid file type. 
                }   ElseIf(!in_array($file_ext[$i], $allow_types)) {

                    $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> Invalide file type.<br />";

                //Check the size of each file
                } Elseif($_FILES['file']['size'][$i] > ($max_file_size*1024)) {

                    $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File to large.<br />";

                // Check if the file already exists on the server..
                } Elseif(file_exists($folder.$file_name[$i].".".$file_ext[$i])) {

                    $error.= "<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> File already exists.<br />";

                } Else {

                    If(move_uploaded_file($_FILES['file']['tmp_name'][$i],$folder.$file_name[$i].".".$file_ext[$i])) {

                        $success.="<b>SUCCESS:</b> ".$_FILES['file']['name'][$i]."<br />";


                    } Else {
                        $error.="<b>FAILED:</b> ".$_FILES['file']['name'][$i]." <b>REASON:</b> General upload failure.<br />";
                    }

                }

            } // If Files

        } // For

    } // Else Total Size

    If(($error=="") AND ($success=="")) {
        $error.="<b>FAILED:</b> No files selected<br />";
    }

    $display_message=$success.$error;

} // $_POST AND !$password_form

/*

0 个答案:

没有答案