本文分享一段php上传图片的代码,通过内置的php函数实现文件上传,有需要的朋友参考下。1,form表单部分
select image:
2,上传图片文件的php代码
$max_size) { echo 文件太大,超过了上传文件的最大限制。the max file size is $max_size kb
n; exit; } # type controlif ( ($http_post_files['userfile']['type']==image/gif) || ($http_post_files['userfile']['type']==image/jpg) || ($http_post_files['userfile']['type']==image/bmp) || ($http_post_files['userfile']['type']==image/png) || ($http_post_files['userfile']['type']==image/jpeg) ) { # if file existif (file_exists($path . $http_post_files['userfile']['name'])) { echo 同名的文件已存在。
; exit; } $res = copy($http_post_files['userfile']['tmp_name'], $path . $http_post_files['userfile']['name']); if (!$res){ echo 上传失败!
; exit; } else{ echo 上传成功!
; } echo file name: .$http_post_files['userfile']['name'].
; echo file size: .$http_post_files['userfile']['size']. bytes
; echo file type: .$http_post_files['userfile']['type'].
; echo view image; } else { echo 错误的文件类型
; exit; } } ?>
注意:在php5以后的代码,已经不再使用这样的方式,改用全局变量$_file来接收上传数据了。
