Upload image
Public functionimages () {$data=$_files[' File ']; Switch($data[' Type ']) { Case' Image/jpeg ':$ext= ' jpg '; Break; Case' Image/gif ':$ext= ' gif '; Break; Case' Image/png ':$ext= ' png '; Break; default:$ext= "; Break; } if($ext){ $file _name=uniqid().‘.‘.$ext;//the new file name $tmp _name=$data[' Tmp_name '];//temporary file name on server $file _size=$data[' Size '];//File Size if($file _size> 204800){ $result=Array(' stat ' = '-2 ', ' str ' = ' picture ' is greater than 200K '); EchoJson_encode ($result); Exit; }Else{ $file _path= ' upload/'.$file _name; $img _path= "http://aaaaaaaaa/upload/".$file _name;//the table alone if(Move_uploaded_file($tmp _name,$file _path) ==true ){ $result=Array(' stat ' = ' 1 ', ' str ' = ' + ' Add picture success ', ' img ' = ' + ')$img _path, ' pic ' =$file _name); }Else{ $result=Array(' stat ' = '-2 ', ' str ' = ' + ' Add picture failed '); } EchoJson_encode ($result); Exit; } }Else{ $result=Array(' stat ' = '-2 ', ' str ' = ' picture ' is not formatted '); EchoJson_encode ($result); Exit; } }
PHP upload images and secure handling