- if (!empty($_FILES[“img”][“name”])) {
- $path=“uppic/”;
- if(!file_exists($path))
- {
-
- mkdir(“$path”, 0700);
- }
-
- $tp = array(“image/gif”,“image/pjpeg”,“image/jpeg”);
-
- if(!in_array($_FILES[“img”][“type”],$tp))
- {
- echo “<script>alert(‘格式不对’);history.go(-1);</script>”;
- exit;
- }
- $filetype = $_FILES[‘img’][‘type’];
- if($filetype == ‘image/jpeg’){
- $type = ‘.jpg’;
- }
- if ($filetype == ‘image/jpg’) {
- $type = ‘.jpg’;
- }
- if ($filetype == ‘image/pjpeg’) {
- $type = ‘.jpg’;
- }
- if($filetype ==’image/gif’){
- $type = ‘.gif’;
- }
- if($_FILES[“img”][“name”])
- {
- $today=date(“YmdHis”);
- $file2 = $path.$today.$type;
- $img = $today.$type;
- $flag=1;
- }
- if($flag) $result=move_uploaded_file($_FILES[“img”][“tmp_name”],$file2);
-
- }
-
-
- 删除图片:
- 复制代码代码如下:
-
- unlink(“uppic/”.$img);
php 图片上传