Skip to content

Commit e92714e

Browse files
committed
修正上传路径,删除多余代码
1 parent e3ee248 commit e92714e

File tree

2 files changed

+24
-32
lines changed

2 files changed

+24
-32
lines changed

Pass-16/index.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111
$filetype = $_FILES['upload_file']['type'];
1212
$tmpname = $_FILES['upload_file']['tmp_name'];
1313

14-
$target_path=UPLOAD_PATH.basename($filename);
14+
$target_path=UPLOAD_PATH.'/'.basename($filename);
1515

1616
// 获得上传文件的扩展名
1717
$fileext= substr(strrchr($filename,"."),1);
1818

1919
//判断文件后缀与类型,合法才进行上传操作
2020
if(($fileext == "jpg") && ($filetype=="image/jpeg")){
21-
if(move_uploaded_file($tmpname,$target_path))
22-
{
21+
if(move_uploaded_file($tmpname,$target_path)){
2322
//使用上传的图片生成新的图片
2423
$im = imagecreatefromjpeg($target_path);
2524

@@ -30,10 +29,9 @@
3029
//给新图片指定文件名
3130
srand(time());
3231
$newfilename = strval(rand()).".jpg";
33-
$newimagepath = UPLOAD_PATH.$newfilename;
34-
imagejpeg($im,$newimagepath);
3532
//显示二次渲染后的图片(使用用户上传图片生成的新图片)
36-
$img_path = UPLOAD_PATH.$newfilename;
33+
$img_path = UPLOAD_PATH.'/'.$newfilename;
34+
imagejpeg($im,$img_path);
3735
@unlink($target_path);
3836
$is_upload = true;
3937
}
@@ -42,8 +40,7 @@
4240
}
4341

4442
}else if(($fileext == "png") && ($filetype=="image/png")){
45-
if(move_uploaded_file($tmpname,$target_path))
46-
{
43+
if(move_uploaded_file($tmpname,$target_path)){
4744
//使用上传的图片生成新的图片
4845
$im = imagecreatefrompng($target_path);
4946

@@ -54,10 +51,10 @@
5451
//给新图片指定文件名
5552
srand(time());
5653
$newfilename = strval(rand()).".png";
57-
$newimagepath = UPLOAD_PATH.$newfilename;
58-
imagepng($im,$newimagepath);
5954
//显示二次渲染后的图片(使用用户上传图片生成的新图片)
60-
$img_path = UPLOAD_PATH.$newfilename;
55+
$img_path = UPLOAD_PATH.'/'.$newfilename;
56+
imagepng($im,$img_path);
57+
6158
@unlink($target_path);
6259
$is_upload = true;
6360
}
@@ -66,8 +63,7 @@
6663
}
6764

6865
}else if(($fileext == "gif") && ($filetype=="image/gif")){
69-
if(move_uploaded_file($tmpname,$target_path))
70-
{
66+
if(move_uploaded_file($tmpname,$target_path)){
7167
//使用上传的图片生成新的图片
7268
$im = imagecreatefromgif($target_path);
7369
if($im == false){
@@ -77,10 +73,10 @@
7773
//给新图片指定文件名
7874
srand(time());
7975
$newfilename = strval(rand()).".gif";
80-
$newimagepath = UPLOAD_PATH.$newfilename;
81-
imagegif($im,$newimagepath);
8276
//显示二次渲染后的图片(使用用户上传图片生成的新图片)
83-
$img_path = UPLOAD_PATH.$newfilename;
77+
$img_path = UPLOAD_PATH.'/'.$newfilename;
78+
imagegif($im,$img_path);
79+
8480
@unlink($target_path);
8581
$is_upload = true;
8682
}

Pass-16/show_code.php

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
$filetype = $_FILES['upload_file']['type'];
1010
$tmpname = $_FILES['upload_file']['tmp_name'];
1111

12-
$target_path=UPLOAD_PATH.basename($filename);
12+
$target_path=UPLOAD_PATH.'/'.basename($filename);
1313

1414
// 获得上传文件的扩展名
1515
$fileext= substr(strrchr($filename,"."),1);
1616

1717
//判断文件后缀与类型,合法才进行上传操作
1818
if(($fileext == "jpg") && ($filetype=="image/jpeg")){
19-
if(move_uploaded_file($tmpname,$target_path))
20-
{
19+
if(move_uploaded_file($tmpname,$target_path)){
2120
//使用上传的图片生成新的图片
2221
$im = imagecreatefromjpeg($target_path);
2322

@@ -28,10 +27,9 @@
2827
//给新图片指定文件名
2928
srand(time());
3029
$newfilename = strval(rand()).".jpg";
31-
$newimagepath = UPLOAD_PATH.$newfilename;
32-
imagejpeg($im,$newimagepath);
3330
//显示二次渲染后的图片(使用用户上传图片生成的新图片)
34-
$img_path = UPLOAD_PATH.$newfilename;
31+
$img_path = UPLOAD_PATH.'/'.$newfilename;
32+
imagejpeg($im,$img_path);
3533
@unlink($target_path);
3634
$is_upload = true;
3735
}
@@ -40,8 +38,7 @@
4038
}
4139

4240
}else if(($fileext == "png") && ($filetype=="image/png")){
43-
if(move_uploaded_file($tmpname,$target_path))
44-
{
41+
if(move_uploaded_file($tmpname,$target_path)){
4542
//使用上传的图片生成新的图片
4643
$im = imagecreatefrompng($target_path);
4744

@@ -52,10 +49,10 @@
5249
//给新图片指定文件名
5350
srand(time());
5451
$newfilename = strval(rand()).".png";
55-
$newimagepath = UPLOAD_PATH.$newfilename;
56-
imagepng($im,$newimagepath);
5752
//显示二次渲染后的图片(使用用户上传图片生成的新图片)
58-
$img_path = UPLOAD_PATH.$newfilename;
53+
$img_path = UPLOAD_PATH.'/'.$newfilename;
54+
imagepng($im,$img_path);
55+
5956
@unlink($target_path);
6057
$is_upload = true;
6158
}
@@ -64,8 +61,7 @@
6461
}
6562

6663
}else if(($fileext == "gif") && ($filetype=="image/gif")){
67-
if(move_uploaded_file($tmpname,$target_path))
68-
{
64+
if(move_uploaded_file($tmpname,$target_path)){
6965
//使用上传的图片生成新的图片
7066
$im = imagecreatefromgif($target_path);
7167
if($im == false){
@@ -75,10 +71,10 @@
7571
//给新图片指定文件名
7672
srand(time());
7773
$newfilename = strval(rand()).".gif";
78-
$newimagepath = UPLOAD_PATH.$newfilename;
79-
imagegif($im,$newimagepath);
8074
//显示二次渲染后的图片(使用用户上传图片生成的新图片)
81-
$img_path = UPLOAD_PATH.$newfilename;
75+
$img_path = UPLOAD_PATH.'/'.$newfilename;
76+
imagegif($im,$img_path);
77+
8278
@unlink($target_path);
8379
$is_upload = true;
8480
}

0 commit comments

Comments
 (0)