PHP Forms Submit pictures, music, video, text, four types are co-submitted to the database

Source: Internet
Author: User
Tags save file

This problem has been bothering me for several days, finally in today let me to solve, hard to hide the excitement.

In fact, there is no contact with this problem, but the form submitted data, and then the picture, four types at the same time submitted also really did not encounter, did a system, which has a function is to submit these four types of data, I can only take this function to finally do, in these days all the functions have been done, Only this one function, I really very upset, these days sleep is not practical, all kinds of form submission, dream is also form submission, wake up I think my heart is so fragile, a little pressure can not bear?

The truth is, no matter what, the problem is solved.

Also very grateful blog Garden of a brother, pointing to me, remote help me to change the environment configuration, solve the most critical issues.

Nonsense is not much to say, let's take a look at the code and

Just for the function, so it's easy to write.

Submit a video There is a prerequisite is to change the PHP configuration file, find this file, change it to specify the maximum MB of the file can be

This must be changed, if not changed, the video is not pass through

Next look at the HTML code

That's the effect of running.

Next, write its processing page

Print first before writing. See if we can get all the data.

On the processing page of it

Save it after you finish writing

Then on the first page of the run, populate the data

Because only print pictures, music, video, so the text can not fill in the first

Click Upload

The data can be passed on successfully, so we'll be successful, more than half.

Let's write these three types of files separately.

//image//Determine if File upload errorif($_files["File"] ["Error"]){    Echo $_files["File"] ["Error"];}Else{    //control the upload file type    if(($_files["File"] ["Type"]== "Image/jpeg" | |$_files["File"] ["Type"]== "Image/png") &&$_files["File"] ["Size"]<1024000)    {        //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        $TP=$filename; }    }    Else    {        Echo"File type is incorrect"; }}if($_files["File1"] ["Error"]){    Echo $_files["File1"] ["Error"];}Else{    //control the upload file type    if(($_files["File1"] ["Type"]== "Audio/mpeg" | |$_files["File1"] ["Type"]== "Mp3/mp3") &&$_files["File1"] ["Size"]<5000000)    {        //Locate the location where the file is stored        $file 1name= "./file/".Date("Ymdhis").$_files["File1"] ["Name"];//added. Splicing//Conversion encoding format        $file 1name=Iconv("UTF-8", "gb2312",$file 1name); //determine if a file exists        if(file_exists($file 1name))        {            Echo"The file already exists!" "; }        Else        {        //Save File        Move_uploaded_file($_files["File1"] ["Tmp_name"],$file 1name);//move an upload file        $yy=$file 1name; }    }    Else    {        Echo"File type is incorrect"; }}//video//Determine if File upload errorif($_files["File2"] ["Error"]){    Echo $_files["File2"] ["Error"];}Else{    //control the upload file type    if(($_files["File2"] ["Type"]== "Video/mp4" | |$_files["File2"] ["Type"]== "Mp4/mp4") &&$_files["File2"] ["Size"]<500000000)    {        //Locate the location where the file is stored        $file 2name= "./file/".Date("Ymdhis").$_files["File2"] ["Name"];//added. Splicing//Conversion encoding format        $file 2name=Iconv("UTF-8", "gb2312",$file 2name); //determine if a file exists        if(file_exists($file 2name))        {            Echo"The file already exists!" "; }        Else        {        //Save File        Move_uploaded_file($_files["File2"] ["Tmp_name"],$file 2name);//move an upload file        $sp=$file 2name; }    }    Else    {        Echo"File type is incorrect"; }}

The main file type here is the type you just printed, and if you just submitted a file that is not in MP4 format, it will output a different type.

Click Upload

The type that appears here is a different kind

So you want to submit what kind of, it must correspond well, otherwise you will be prompted the file type is incorrect

Next, write the complete code for the processing page.

<?PHP$wz=$_post["WZ"];//var_dump ($_files["file"]); The index writes its name value//var_dump ($_files["file1");//var_dump ($_files["file2"]);include("dbda.php");$DX=NewDbda ();//image//Determine if File upload errorif($_files["File"] ["Error"]){    Echo $_files["File"] ["Error"];}Else{    //control the upload file type    if(($_files["File"] ["Type"]== "Image/jpeg" | |$_files["File"] ["Type"]== "Image/png") &&$_files["File"] ["Size"]<1024000)    {        //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        $TP=$filename; }    }    Else    {        Echo"File type is incorrect"; }}if($_files["File1"] ["Error"]){    Echo $_files["File1"] ["Error"];}Else{    //control the upload file type    if(($_files["File1"] ["Type"]== "Audio/mpeg" | |$_files["File1"] ["Type"]== "Mp3/mp3") &&$_files["File1"] ["Size"]<5000000)    {        //Locate the location where the file is stored        $file 1name= "./file/".Date("Ymdhis").$_files["File1"] ["Name"];//added. Splicing//Conversion encoding format        $file 1name=Iconv("UTF-8", "gb2312",$file 1name); //determine if a file exists        if(file_exists($file 1name))        {            Echo"The file already exists!" "; }        Else        {        //Save File        Move_uploaded_file($_files["File1"] ["Tmp_name"],$file 1name);//move an upload file        $yy=$file 1name; }    }    Else    {        Echo"File type is incorrect"; }}//video//Determine if File upload errorif($_files["File2"] ["Error"]){    Echo $_files["File2"] ["Error"];}Else{    //control the upload file type    if(($_files["File2"] ["Type"]== "Application/octet-stream" | |$_files["File2"] ["Type"]== "FLV/QSV") &&$_files["File2"] ["Size"]<500000000)    {        //Locate the location where the file is stored        $file 2name= "./file/".Date("Ymdhis").$_files["File2"] ["Name"];//added. Splicing//Conversion encoding format        $file 2name=Iconv("UTF-8", "gb2312",$file 2name); //determine if a file exists        if(file_exists($file 2name))        {            Echo"The file already exists!" "; }        Else        {        //Save File        Move_uploaded_file($_files["File2"] ["Tmp_name"],$file 2name);//move an upload file        $sp=$file 2name; }    }    Else    {        Echo"File type is incorrect"; }}$sql= "INSERT into TP values ('", ' {$TP}‘,‘{$yy}‘,‘{$sp}‘,‘{$wz}‘)"; $r=$DX->query ($sql, 0); if($r)         {          Echo"Submit Success"; }         Else         {            Echo"Commit Failed"; }

Before you write, it's best to print out what type of video you want to submit, and also the music

The database I'm using is this

It is also important to note that the file name does not contain Chinese characters.

Create a new file folder in the same directory, and all of your submitted files will be saved in this folder.

Let's try it down here.

Click Upload

Submit Success

Check out the database.

Add success!

If you need to, read through the data.

PHP Forms Submit pictures, music, video, text, four types are co-submitted to the database

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.