安卓/html上传
后端php接收存储文件后台死活传不上文件,索性就直接写了前端demo和后端上传接口,给自己和后台对比试用...AkkunYo> 做上传的时候,后台死活传不上文件,索性就直接写了前端demo和后端上传接口,做测试用
##### 后端php接收文件并且存储在uploadfiles文件夹(自定义)
upload.php
```php
<?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
```html
<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>
```
方式二:安卓上传
```java
public class Notes{
public void test(){
String a ="字符";
}
}
```