Home  >  Article  >  Backend Development  >  thinkphp3.1 多文件上传图片和文档,如何保存在不同的文件夹

thinkphp3.1 多文件上传图片和文档,如何保存在不同的文件夹

WBOY
WBOYOriginal
2016-06-13 12:00:22956browse

thinkphp3.1 多文件上传图片和文档,怎么保存在不同的文件夹?
thinkphp3.1 上传图片和文档,怎么分开保存?
------解决方案--------------------
如果你愿意修改 UploadFile.class.php 文件的话,事情还是有转机的
把 getSaveName 方法中的(408行附近)
$saveName = $rule().".".$filename['extension'];
改成
$saveName = $rule($filename).".".$filename['extension'];

然后

$upload->savePath = '';<br />$upload->saveRule = 'myFunction';

定义函数
function myFunction($filename) {<br />  $p = in_array($filename['extension'], array('gif', 'jpg', 'png')) ? '图片路径' : '文档路径';<br />  return $p . $filename['name'];<br />}

由于之后还会加上后缀,所以 $filename['name'] 怎么变形你可随意

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn