Front-End Interaction summary 2: Uploading form data using PHP

Source: Internet
Author: User

1: Upload a form using PHP

1.1 Data collection for form form forms

HTML page:

Code explanation: The core module is the property of the form:

-- How to submit: method= "POST" -- Specify the Name property : For example name= "username"-- Specify file upload format for form : enctype= "Multipart/form-data" 2 Click the Submit button after the background action

2.1 Get the image data by $_files the Hyper global variable:

Two-dimensional array, you can get the content of the submission data uploaded by the form.

  Array  (      [PHOTO] = array          (              [name] + picture.jpg   file name              [Type] = = Image/jpeg     File Type              [Tmp_name] = C:\Users\Jepson\AppData\Local\Temp\phpBF97.tmp  temporarily stored path              [ERROR] = 0    error code, if 0 Indicates no error              [size] = 17552  file size, unit byte 17kb or so)  

2.2 PHP Image dump:

  //1 Getting an array of files  $file=$_files[' Photo ']; if($file[' error '] = = = 0) {//2 need to dump files    $ftmp=$file[' Tmp_name '];//3 Get temporary file path//4 intercept suffix name    $name=$file[' Name '];//source file name 1.gif    $ext=STRRCHR($name, "." );//. gif//5 randomly generated file name    $newName= Time().Rand(10000, 99999).$ext; //move_uploaded_file ("Temporary File path", "Store file path")//6 dump file    Move_uploaded_file($ftmp, "./upload/".$newName );
}

2.3 by $_post Super global variable gets post data, saved in global variable.

   $username  = $_post  [' username '  ];   $nickname  = $_post  [' nickname '  Span style= "COLOR: #000000" >);   $age  = $_post  [' Age ' );   $photo  = ""; //  picture address   

2.4 Preparing the SQL statement for database write operations

Inserting data

$sql = "insert into Stu (name, nickname, age, tel, sex, photo, classid)          values ('$username  ', '$nickname$age, '$tel', '$sex', '$photo$class )";

2.5 Determine if the insert succeeds and jump action

if $sql )     {echo "add Success";     // Jump to Student list php file    Header (' location:studentList.php ');  }   Else {    echo "add failed";  }

Note: my_exec ($sql)--php executes the SQL statement.

Front-End Interaction summary 2: Uploading form data using 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.