无法获得Php限制以使用HTML输入标签进行歌曲上传

时间:2013-11-10 17:07:27

标签: php html

您好我正在尝试使用我的php上传脚本来制作限制 当我在浏览器中运行时,确定人们只会上传音乐 我总是上传faild所有发布我的代码

    <?php

    // This  PHP5 file is used to move an uploaded song file to its final
    // destination. The song is scaled as part of the process.

    // A normal HTML upload form will serve as the user interface  for the
    // upload.  The  song  file should be  submitted  using a  field named
    // "song". 

    // set database connection
    require("------.php");

    // lets get our posts //
       $song     = $_FILES['song'];
    // folder that will hold songs
       $songpath = "songs/";
    // song-file pathname
       $songpath .= $song["name"];

    //---------------------------------------------------------------
    //  this  file  is  going to add  restrictions to the song  form



       $ftype  = $_FILES["song"]["type"  ];
       $xerror = $_FILES["song"]["error" ];
       $xsize  = $_FILES["song"]["size"  ];

        if (($ftype == "audio/mp3"  )
         || ($ftype == "audio/ogg"  )
         || ($ftype == "audio/wav"  )
         || ($ftype == "audio/midi" ))

        {
            $it_is_a_song = 1;
        }
        else
        {
            $it_is_a_song = 0;
        }

        if ($it_is_a_song && ($xsize < 20971520) && ($xerror == 0))
        {
            $it_is_good = 1;
        }
        else
        {
            $it_is_good = 0;
        }



    //-----------------------------------------------------------------
    print <<<END
    <html>
    <title>You Must Party Upload Results</title>
    <body>
    END;

    // move the file from the tmp folder to the song folder
    if ( $it_is_good &&
         move_uploaded_file ($song['tmp_name'], $songpath))
    {
         print "<p>Upload succeeded thank you</p>\n";
    }
    else
    {
        print "<p>Upload failed, sorry</p>\n";
    }

    print <<<END
    <p>
    To continue, <a href="images.php">click here.</a>
    </p>
    </body>
    </html>
    END;

    ?>

1 个答案:

答案 0 :(得分:0)

$_FILES["song"]["type"]将返回mime类型,并且song mime类型不存在,因此它将始终失败。

而是使用audio,例如。 audio/ogg