<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
- Through forms
<input type= "File" Name= "MyFile" accept= "Mime_type"/>mime_type: image/jpeg,image/png,image/gif ...
- 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 );}
- Verify that the picture is true
if (!getimagesize ($tmp_name)) { exit("Not a real picture");}
PHP--Uploading files