Form submission Music file (PHP)

Source: Internet
Author: User
Tags save file

Use the point of free time to write a blog, the most recent projects need to submit the form of audio, pictures, various types, put it into the database, here first of all, the music file form submission bar, after a few days to update the input database, first look at the effect

Click to browse

Will come out preview and click on the MP3 file

Open play also plays normally

Let's change a picture and try to pass it on.

Submit Picture

Click Submit

The commit was unsuccessful because this only allows file submissions in MP3 format

Just haven't seen MP3 's submission, submit the MP3 file below

Click Submit

Because there is no jump page set for it, it is still on its processing page

and the image upload principle is the same, image upload in my previous blog has, the same need to create a new folder in their own directory

And the submitted content must be stored in this folder.

See if there's a MP3 file that we just submitted.

Run successfully

If I submit it again, there will be

Click Submit

Check the folder.

Still have.

Let's take a look at the source code of our

First look at the page

<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title>Untitled Document</title></Head><Scriptsrc= "Http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></Script><Body><Divclass= "Box_input"style= "margin-bottom:20px;">                                        <formAction= "shiyancl.php"Method= "POST"style= "width:960px;"enctype= "Multipart/form-data">                        <inputID= "Test"style= "Display:inline-block;"type= "File"name= "File"/>                        <AudioID= "Audio"Controls AutoPlay=""style= "Display:none; "></Audio>                            <inputtype= "Submit"ID= "Mp3_submit"style= "display:none;margin-left:25px;"type= "button"value= "Submit"/>                    </form>                                               </Div></Body><Script>             //Recording Upload            $(function () {                $("#test"). Change (function () {                    varObjurl=Getobjecturl ( This. files[0]); $("#audio"). attr ("src", Objurl); $("#audio")[0].pause (); $("#audio"). Show (); $("#mp3_submit"). Show () GetTime ();            });            }); <!--Get time-compatible browser for MP3 files -            functionGetTime () {setTimeout (function () {                    varDuration= $("#audio")[0].duration; if(IsNaN (duration)) {getTime (); }                    Else{console.info ("the total time of the song is:"+$("#audio")[0].duration+"seconds")                    }                }, Ten); }            <!--convert the file to a readable URL -            functionGetobjecturl (file) {varURL= NULL; if(Window.createobjecturl!=undefined) { //BasicURL=window.createobjecturl (file); } Else if(window. URL!=undefined) { //Mozilla (Firefox)URL=window.                Url.createobjecturl (file); } Else if(Window.webkiturl!=undefined) { //WebKit or ChromeURL=Window.webkitURL.createObjectURL (file); }                returnURL; }            </Script></HTML>

And look at it. The code file name of the Submit page is shiyancl.php

<?PHP//var_dump ($_files["file"]); Index write its name value//Determine if File upload errorif($_files["File"] ["Error"]){    Echo $_files["File"] ["Error"];}Else{    //control the upload file type    if(($_files["File"] ["Type"]== "Audio/mpeg" | |$_files["File"] ["Type"]== "Mp3/mp3") &&$_files["File"] ["Size"]<500000)    {        //Locate the location where the file is stored        $filename= "./file/".Date("Ymdhis").$_files["File"] ["Name"];//added. Splicing//Conversion encoding format        $filename=Iconv("UTF-8", "gb2312",$filename); //determine if a file exists        if(file_exists($filename))        {            Echo"The file already exists!" "; }        Else        {        //Save File        Move_uploaded_file($_files["File"] ["Tmp_name"],$filename);//move an upload file        }            }    Else    {        Echo"File type is incorrect"; }}

Before you write, you can use Var_dump to output something you want to submit.

It's going to give you back the data type or something.

Some things can be changed according to this

I will continue to upload the other functions, I hope it will be helpful to everyone

Form submission Music file (PHP)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.