1:
$now=date("Ymd");
2:
to标签用可以放多个实现多文件命名方式to[]
在程序里面
$tos=$_POST[to];
foreahc($tos as $to){
//里面操作
}
其它操作多个是建立在操作一个的基础上
$now=date("Ymd");
2:
to标签用可以放多个实现多文件命名方式to[]
在程序里面
$tos=$_POST[to];
foreahc($tos as $to){
//里面操作
}
其它操作多个是建立在操作一个的基础上
<input type="file" name="from" value="Submit">
file的文件名相同,其实只上传一个
正确应该
<input type="file" name="from[]" value="Submit">
<input type="file" name="from[]" value="Submit">2 多个上传文件,只需要处理$_FILES就可以了,循环遍历操作就可以了.
如果不太明白,var_dump($_FILES);不过是多维数组而矣3 用file_exists()可以检查是否有重名的文件,如果有,则copy到另一个目录.
谢谢楼上的,1中要想传很多文件的话也是要很多 button 呀,不方便,有没有好方法呢,
2中贴点代码吧,
3 问题是这样的,
比如我有from\a.txt b.txt 和 to\a.txt b.txt c.txt (from 和 to 为文件夹)
我要把from\a.txt copy到 to\中,不过要先把to\a.txt 文件命名为 a.txt20081204 再把from\a.txt copy过来,
这样重命名时就会有目录的问题,我弄不了,要是文件一同一目录我用rename(a.txt,aa.txt)就可;
大家帮我想想。
2 代码<form action="upload.php" method="post" enctype="multipart/form-data" name="upload_img">
input type='file' name='attachments[]' value='<{$arrClass.name}>' size='35'><br/>
<input type='file' name='attachments[]' value='<{$arrClass.name}>' size='35'><br/>
<input type='file' name='attachments[]' value='<{$arrClass.name}>' size='35'><br/>
<input type="submit" value="上传" >
</form>
function getRandomName()
{
$strTime = date('YmdHis') . rand(1,1000);
return md5($strTime);
}$arrFileName = $_FILES['attachments']['name'];
$arrTmpName = $_FILES['attachments']['tmp_name'];
$arrError = $_FILES['attachments']['error'];
foreach($arrFileName as $key=>$value)
{
if($arrError[$key] != 0)
{
echo $arrError[$key];
continue;
}
//获得后缀
$strExtend = "." . pathinfo($value, PATHINFO_EXTENSION);
$strSrcFileName = $arrTmpName[$key];
$strClientFileName = $arrFileName[$key];
//检查是否匹配
if(preg_match("/\.(exe|php|js|htm|html|bat)/i", $strExtend))
{
echo $strExtend . "<br/>";
continue;
}
//构造文件名
$strFileName = getRandomName() . $strExtend;
$strDestName = $tmpDir . $strFileName;
move_uploaded_file($strSrcFileName, $strDestName);
}
3 先检查b中是否存在 a.txt,注意是a.txt,不是a/a.txt,如果存在,改名,然后copy.
<input type="file" name="files[]" />
<input type="file" name="files[]" />这样就可以了,一个按钮提交,哪来很多按钮
<form action="upload.php" method="post" enctype="multipart/form-data" name="upload_img">
input type='file' name='attachments[]' value='<{$arrClass.name}>' size='35'><br/>
<input type='file' name='attachments[]' value='<{$arrClass.name}>' size='35'><br/>
<input type='file' name='attachments[]' value='<{$arrClass.name}>' size='35'><br/>
<input type="submit" value="上传" >
</form> $arrFileName = $_FILES['attachments']['name'];
$arrTmpName = $_FILES['attachments']['tmp_name'];
$arrType=$_FILES['userfile']['type'];
$arrError = $_FILES['attachments']['error'];
foreach($arrFileName as $key=>$value)
{
if($arrError[$key] != 0)
{
echo $arrError[$key]."<script>history.go(-1);</script>";
exit;
}
if ($arrType != 'text/plain')
{
echo "<script>alert('Problem: file is not plain text'); history.go(-1);</script>";
exit;
}
$upfile='../b/'.$arrFileName;
$name=explode('.',basename($arrFileName));
$FilechangeName=$name[0].".".$name[1].date('Ymd');
rename('../b/'.$arrFileName,'../b/'.$FilechangeName);
if (is_uploaded_file($arrTmpName))
{
if (!move_uploaded_file($arrTmpName, $upfile))
{
echo "<script>alert('Problem: Could not move file to destination directory'); history.go(-1);</script>";
exit;
}
else
{
echo "<script>alert('上传成功');</script>";
}
}
else
{
echo "<script>alert('Problem: Possible file upload attack. Filename:$arrFileName'); history.go(-1);</script>";
exit;
}}
不过有二个问题:
1.老提示 Problem: file is not plain text
2.文件都不知传到哪去了。
改成$arrType=$_FILES['attachments']['type'];
试下。