文章

后端php接收文件并且存储在uploadfiles文件夹(自定义)

后端php接收存储文件后台死活传不上文件,索性就直接写了前端demo和后端上传接口,给自己和后台对比试用…

做上传的时候,后台死活传不上文件,索性就直接写了前端demo和后端上传接口,做测试用

后端php接收文件并且存储在uploadfiles文件夹(自定义)

upload.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php

$target\_path = "uploadfiles/".$\_FILES ['file'] ['name']; //接收文件目录

if (move\_uploaded\_file ( $\_FILES ['file'] ['tmp\_name'], iconv("UTF-8","gb2312",$target\_path) )) {

$array = array ("code" => "1", "message" => "https://www.zkyml.com/uploadfiles/".$\_FILES ['file'] ['name'] );

echo json\_encode ( $array );

} else {

$array = array ("code" => "0", "message" => "上传失败,请重试" . $\_FILES ['file'] ['error'] );

echo json\_encode ( $array );

}

?>
前端

方式一:html上传

test.html

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<html>

<body>

<form action="upload.php" method="post" enctype="multipart/form-data">

<label for="file">Filename:</label>

<input type="file" name="file" id="file"/>

<br/>

<input type="submit" name="file" value="Submit"/>

</form>

</body>

</html>

方式二:安卓上传

1
2
3
4
5
6
7
8
9
public class Notes{

public void test(){

String a ="字符";

}

}
本文由作者按照 CC BY 4.0 进行授权