PHP--Uploading files

Source: Internet
Author: User
Tags form post

<title>php– Uploading Files</title> php– uploading a file table of Contents
    • /etc/php.ini configuration file Information
    • Error value
    • Uploading files
    • Uploading Multiple files
    • Determine if the file is a post
    • Set the allowed file types
/etc/php.ini configuration file Information
File_uploads = Onupload_max_filesize = 100m       # The maximum allowable upload file size post_max_size = 100M             # refers to the maximum value that can be received by the form POST to PHP Upload_ Tmp_dir =/tmp            # temp file directory max_file_uploads =            # maximum number of files
Max_execution_time =         # maximum time value per PHP page run (seconds) memory_limit = 128M              # maximum memory consumed per PHP page max_input_time =              Maximum time allowed for data (seconds) Max_input_nesting_level =     # of the nesting depth of input variables
Error value
0 indicates that the file size of Ok1 uploaded exceeds upload_max_filesize2 over max_file_size   #  <input type= "hidden" name= "max_file_size" value= "30000" >3 file only part of the uploaded 4 file was not uploaded 6 did not find temp directory 7 file write failed (possibly a permissions issue) 8 was interrupted by PHP extension
Uploading files
<form  action  = method  = "post"  enctype  = "Multipart/form-data"  > <input  type  = "file"  name  = "myfile"  ><< Span style= "color: #87cefa;" >br /> <type  = "submit"  value  = "Upload file"  ></form ; 
$filename=$_files[' myfile '][' name '];$type=$_files[' myfile '][' type '];$Tmp_name=$_files[' myfile '][' Tmp_name '];$size=$_files[' myfile '][' Size '];$Error=$_files[' myfile '][' ERROR '];$Destination= DirName (__file__).'/upload/'.$filename; Move_uploaded_file ($Tmp_name,$Destination);
Uploading Multiple files
<form Action="doaction.php" Method="POST" enctype="Multipart/form-data"> <input type="File" name="myfile[]"><BR/> <input type="File" name="myfile[]"><BR/> <input type="Submit" value="Upload file"></form>
foreach($myfile  as $file) {$filename=$_files[' file '][' name '];$type=$_files[' file '][' type '];$Tmp_name=$_files[' file '][' Tmp_name '];$size=$_files[' file '][' Size '];$Error=$_files[' file '][' ERROR '];} ...
Determine if the file is a post
if (!is_uploaded_file ($tmp_name)) {    exit("File not uploaded by HTTP POST");}
Set the allowed file types
  1. Through forms
    <input type= "File" Name= "MyFile" accept= "Mime_type"/>mime_type:  image/jpeg,image/png,image/gif ...
  2. through PHP authentication
    Get the suffix name:
     $ext = Strtolower (End (Explode ('. ', $filename))); $ext = PathInfo ($ filename) [' extension ']; 
    $   Arrext  = [ ' jpeg ' ,  ' png ' ,  ' gif ' ]; if  (! In_array ($  ext , $  arrext  ) {exit  ( "illegal file type );} 
  3. Verify that the picture is true
    if (!getimagesize ($tmp_name)) {    exit("Not a real picture");}

PHP--Uploading files

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.