关于ci上传后文件格式总是application/octet-stream解决方法_IT_小学生_新浪博客

 
  
$config['upload_path']      = SITE_UPLOADS;
$config['allowed_types'] = 'xls|xlsx';
$config['max_size'] = 100;

$this->load->library('upload', $config);

if ($this->upload->do_upload('file'))
最近用CodeIgniter做的一个项目,上传xml文件的时候一直提示文件类型错误,后来打印出上传的xml文件类型为application/octet-stream,查看对比了
'xls'   => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'),'xlsx'  => array'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip',
'word' => array'application/msword',,
文件类型和xml不匹配!

原因分析:是因为php配置文件没有开启extension=php_fileinfo.dll造成的。
解决方法:打开php目录下的php.ini文件,删除extension=php_fileinfo.dll前面的分号(;),然后重启apache服务即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 分页展示Hdfs文件列表 前端代码: ```html <!-- 分页插件 --> <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script> <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> <table class="table table-hover"> <thead> <tr> <th>#</th> <th>文件名</th> <th>大小</th> <th>修改时间</th> <th>操作</th> </tr> </thead> <tbody> <c:forEach items="${hdfsFiles}" var="hdfsFile" varStatus="status"> <tr> <td>${status.index+1}</td> <td><a href="#">${hdfsFile.name}</a></td> <td>${hdfsFile.size}</td> <td>${hdfsFile.modificationTime}</td> <td> <button class="btn btn-danger" onclick="deleteFile('${hdfsFile.path}')">删除</button> <button class="btn btn-success" onclick="downloadFile('${hdfsFile.path}')">下载</button> </td> </tr> </c:forEach> </tbody> </table> <div class="text-center"> <ul class="pagination"> <c:choose> <c:when test="${pageInfo.pageNum == 1}"> <li class="disabled"><a href="#">首页</a></li> <li class="disabled"><a href="#">上一页</a></li> </c:when> <c:otherwise> <li><a href="?pageNum=1">首页</a></li> <li><a href="?pageNum=${pageInfo.prePage}">上一页</a></li> </c:otherwise> </c:choose> <c:forEach begin="${pageInfo.navigateFirstPage}" end="${pageInfo.navigateLastPage}" var="i"> <c:choose> <c:when test="${i == pageInfo.pageNum}"> <li class="active"><a href="#">${i}</a></li> </c:when> <c:otherwise> <li><a href="?pageNum=${i}">${i}</a></li> </c:otherwise> </c:choose> </c:forEach> <c:choose> <c:when test="${pageInfo.pageNum == pageInfo.pages}"> <li class="disabled"><a href="#">下一页</a></li> <li class="disabled"><a href="#">尾页</a></li> </c:when> <c:otherwise> <li><a href="?pageNum=${pageInfo.nextPage}">下一页</a></li> <li><a href="?pageNum=${pageInfo.pages}">尾页</a></li> </c:otherwise> </c:choose> </ul> </div> ``` 后端代码: ```java @RequestMapping("/listFiles") public ModelAndView listFiles(@RequestParam(defaultValue = "1") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize) throws Exception { ModelAndView mv = new ModelAndView("fileList"); FileSystem fs = FileSystem.get(new URI("hdfs://localhost:9000"), new Configuration(), "root"); RemoteIterator<LocatedFileStatus> fileStatusListIterator = fs.listFiles(new Path("/"), true); List<HdfsFile> hdfsFiles = new ArrayList<>(); while (fileStatusListIterator.hasNext()) { LocatedFileStatus fileStatus = fileStatusListIterator.next(); HdfsFile hdfsFile = new HdfsFile(); hdfsFile.setName(fileStatus.getPath().getName()); hdfsFile.setPath(fileStatus.getPath().toString()); hdfsFile.setSize(fileStatus.getLen()); hdfsFile.setModificationTime(fileStatus.getModificationTime()); hdfsFiles.add(hdfsFile); } PageHelper.startPage(pageNum, pageSize); PageInfo<HdfsFile> pageInfo = new PageInfo<>(hdfsFiles); mv.addObject("hdfsFiles", pageInfo.getList()); mv.addObject("pageInfo", pageInfo); return mv; } ``` 2. 上传文件 前端代码: ```html <form action="${pageContext.request.contextPath}/uploadFile" method="post" enctype="multipart/form-data"> <div class="form-group"> <label>选择文件</label> <input type="file" name="file"> </div> <button type="submit" class="btn btn-primary">上传</button> </form> ``` 后端代码: ```java @RequestMapping("/uploadFile") public String uploadFile(@RequestParam("file") MultipartFile file) throws IOException, URISyntaxException { FileSystem fs = FileSystem.get(new URI("hdfs://localhost:9000"), new Configuration(), "root"); Path dst = new Path("/" + file.getOriginalFilename()); FSDataOutputStream outputStream = fs.create(dst); IOUtils.copyBytes(file.getInputStream(), outputStream, 4096, true); return "redirect:/listFiles"; } ``` 3. 删除文件 前端代码: ```html <button class="btn btn-danger" onclick="deleteFile('${hdfsFile.path}')">删除</button> ``` 后端代码: ```java @RequestMapping("/deleteFile") public String deleteFile(String path) throws IOException, URISyntaxException { FileSystem fs = FileSystem.get(new URI("hdfs://localhost:9000"), new Configuration(), "root"); Path dst = new Path(path); fs.delete(dst, true); return "redirect:/listFiles"; } ``` 4. 下载文件 前端代码: ```html <button class="btn btn-success" onclick="downloadFile('${hdfsFile.path}')">下载</button> ``` 后端代码: ```java @RequestMapping("/downloadFile") public ResponseEntity<byte[]> downloadFile(String path) throws IOException, URISyntaxException { FileSystem fs = FileSystem.get(new URI("hdfs://localhost:9000"), new Configuration(), "root"); Path dst = new Path(path); FSDataInputStream inputStream = fs.open(dst); byte[] bytes = IOUtils.toByteArray(inputStream); HttpHeaders headers = new HttpHeaders(); headers.setContentDispositionFormData("attachment", dst.getName()); headers.setContentType(MediaType.APPLICATION_OCTET_STREAM); return new ResponseEntity<>(bytes, headers, HttpStatus.CREATED); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值