|
11 | 11 | $filetype = $_FILES['upload_file']['type']; |
12 | 12 | $tmpname = $_FILES['upload_file']['tmp_name']; |
13 | 13 |
|
14 | | - $target_path=UPLOAD_PATH.basename($filename); |
| 14 | + $target_path=UPLOAD_PATH.'/'.basename($filename); |
15 | 15 |
|
16 | 16 | // 获得上传文件的扩展名 |
17 | 17 | $fileext= substr(strrchr($filename,"."),1); |
18 | 18 |
|
19 | 19 | //判断文件后缀与类型,合法才进行上传操作 |
20 | 20 | if(($fileext == "jpg") && ($filetype=="image/jpeg")){ |
21 | | - if(move_uploaded_file($tmpname,$target_path)) |
22 | | - { |
| 21 | + if(move_uploaded_file($tmpname,$target_path)){ |
23 | 22 | //使用上传的图片生成新的图片 |
24 | 23 | $im = imagecreatefromjpeg($target_path); |
25 | 24 |
|
|
30 | 29 | //给新图片指定文件名 |
31 | 30 | srand(time()); |
32 | 31 | $newfilename = strval(rand()).".jpg"; |
33 | | - $newimagepath = UPLOAD_PATH.$newfilename; |
34 | | - imagejpeg($im,$newimagepath); |
35 | 32 | //显示二次渲染后的图片(使用用户上传图片生成的新图片) |
36 | | - $img_path = UPLOAD_PATH.$newfilename; |
| 33 | + $img_path = UPLOAD_PATH.'/'.$newfilename; |
| 34 | + imagejpeg($im,$img_path); |
37 | 35 | @unlink($target_path); |
38 | 36 | $is_upload = true; |
39 | 37 | } |
|
42 | 40 | } |
43 | 41 |
|
44 | 42 | }else if(($fileext == "png") && ($filetype=="image/png")){ |
45 | | - if(move_uploaded_file($tmpname,$target_path)) |
46 | | - { |
| 43 | + if(move_uploaded_file($tmpname,$target_path)){ |
47 | 44 | //使用上传的图片生成新的图片 |
48 | 45 | $im = imagecreatefrompng($target_path); |
49 | 46 |
|
|
54 | 51 | //给新图片指定文件名 |
55 | 52 | srand(time()); |
56 | 53 | $newfilename = strval(rand()).".png"; |
57 | | - $newimagepath = UPLOAD_PATH.$newfilename; |
58 | | - imagepng($im,$newimagepath); |
59 | 54 | //显示二次渲染后的图片(使用用户上传图片生成的新图片) |
60 | | - $img_path = UPLOAD_PATH.$newfilename; |
| 55 | + $img_path = UPLOAD_PATH.'/'.$newfilename; |
| 56 | + imagepng($im,$img_path); |
| 57 | + |
61 | 58 | @unlink($target_path); |
62 | 59 | $is_upload = true; |
63 | 60 | } |
|
66 | 63 | } |
67 | 64 |
|
68 | 65 | }else if(($fileext == "gif") && ($filetype=="image/gif")){ |
69 | | - if(move_uploaded_file($tmpname,$target_path)) |
70 | | - { |
| 66 | + if(move_uploaded_file($tmpname,$target_path)){ |
71 | 67 | //使用上传的图片生成新的图片 |
72 | 68 | $im = imagecreatefromgif($target_path); |
73 | 69 | if($im == false){ |
|
77 | 73 | //给新图片指定文件名 |
78 | 74 | srand(time()); |
79 | 75 | $newfilename = strval(rand()).".gif"; |
80 | | - $newimagepath = UPLOAD_PATH.$newfilename; |
81 | | - imagegif($im,$newimagepath); |
82 | 76 | //显示二次渲染后的图片(使用用户上传图片生成的新图片) |
83 | | - $img_path = UPLOAD_PATH.$newfilename; |
| 77 | + $img_path = UPLOAD_PATH.'/'.$newfilename; |
| 78 | + imagegif($im,$img_path); |
| 79 | + |
84 | 80 | @unlink($target_path); |
85 | 81 | $is_upload = true; |
86 | 82 | } |
|
0 commit comments