PHP の複数画像のアップロード値の問題
3 つの画像アップロード関数を指定しましたが、画像 1 は自動的に名前変更できましたが、画像 2 と 3 は自動的に変更できませんでした。自動的に名前が変更されるのですが、どうすれば変更できますか?
$uploaddir = "uploadfiles/";//设置文件保存目录 注意包含/ <br />$type=array("jpg","gif","bmp","jpeg","png");//设置允许上传文件的类型 <br />$patch="uploadfiles/";//程序所在路径 <br /><br />//获取文件后缀名函数 <br />function fileext($filename) <br />{ <br />return substr(strrchr($filename, '.'), 1); <br />} <br />//获取文件后缀名函数 <br />function fileext2($filename2) <br />{ <br />return substr(strrchr($filename2, '.'), 1); <br />} <br />//获取文件后缀名函数 <br />function fileext3($filename3) <br />{ <br />return substr(strrchr($filename3, '.'), 1); <br />} <br />//生成随机文件名函数 <br />function random($length) <br />{ <br />$hash = 'java-'; <br />$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; <br />$max = strlen($chars) - 1; <br />mt_srand((double)microtime() * 1000000); <br />for($i = 0; $i < $length; $i++) <br />{ <br />$hash .= $chars[mt_rand(0, $max)]; <br />} <br />return $hash; <br />} <br />$a=strtolower(fileext($_FILES['img1']['name'])); <br />$b=strtolower(fileext2($_FILES['img2']['name'])); <br />$c=strtolower(fileext3($_FILES['img3']['name'])); <br />//判断文件类型 <br />if(!in_array(strtolower(fileext($_FILES['img1']['name'])),$type)) <br />{ <br />$text=implode(",",$type); <br />echo "您只能上传以下类型文件: ",$text,"<br>"; <br />} <br />//生成目标文件的文件名 <br />else{ <br />$filename=explode(".",$_FILES['img1']['name']); <br />$filename2=explode(".",$_FILES['img2']['name']);<br />$filename3=explode(".",$_FILES['img3']['name']);<br />do <br />{ <br />$filename[0]=random(10); //设置随机数长度 <br />$name=implode(".",$filename); <br />//$name1=$name.".Mcncc"; <br />$uploadfile=$uploaddir.$name; <br />$filename[1]=random(10); //设置随机数长度 <br />$name2=implode(".",$filename2); <br />//$name1=$name.".Mcncc"; <br />$uploadfile2=$uploaddir.$name2; <br />$filename[2]=random(10); //设置随机数长度 <br />$name3=implode(".",$filename3); <br />//$name1=$name.".Mcncc"; <br />$uploadfile3=$uploaddir.$name3; <br />} <br />while(file_exists($uploadfile)); <br />if (move_uploaded_file($_FILES['img1']['tmp_name'],$uploadfile)){ <br /><br />//if(is_uploaded_file($_FILES['file']['tmp_name'])){ <br />//输出图片预览 <br />//echo "<center>您的文件已经上传完毕 上传图片预览: </center><br><center><img src='$uploadfile'></center>"; <br />//echo"<br><center><a href='javascript:history.go(-1)'>继续上传</a></center>"; <br />//} <br />//else{ <br />//echo "上传失败!"; <br />} <br />if (move_uploaded_file($_FILES['img2']['tmp_name'],$uploadfile2)){ <br /><br />//if(is_uploaded_file($_FILES['file']['tmp_name'])){ <br />//输出图片预览 <br />//echo "<center>您的文件已经上传完毕 上传图片预览: </center><br><center><img src='$uploadfile'></center>"; <br />//echo"<br><center><a href='javascript:history.go(-1)'>继续上传</a></center>"; <br />//} <br />//else{ <br />//echo "上传失败!"; <br />}<br />if (move_uploaded_file($_FILES['img3']['tmp_name'],$uploadfile3)){ <br /><br />//if(is_uploaded_file($_FILES['file']['tmp_name'])){ <br />//输出图片预览 <br />//echo "<center>您的文件已经上传完毕 上传图片预览: </center><br><center><img src='$uploadfile'></center>"; <br />//echo"<br><center><a href='javascript:history.go(-1)'>继续上传</a></center>"; <br />//} <br />//else{ <br />//echo "上传失败!"; <br />}<br />} <br /><br /><br />$SourceFileName=$uploadfile;<br />$SourceFileName2=$uploadfile2;<br />$SourceFileName3=$uploadfile3;
<br />do <br />{ <br />$filename[0]=random(10); //设置随机数长度 <br />$name=implode(".",$filename); <br />//$name1=$name.".Mcncc"; <br />$uploadfile=$uploaddir.$name; <br />$filename[1]=random(10); //设置随机数长度 <br />$name2=implode(".",$filename2); <br />//$name1=$name.".Mcncc"; <br />$uploadfile2=$uploaddir.$name2; <br />$filename[2]=random(10); //设置随机数长度 <br />$name3=implode(".",$filename3); <br />//$name1=$name.".Mcncc"; <br />$uploadfile3=$uploaddir.$name3; <br />}<br />
<br /><?php<br />$uploaddir = "uploadfiles/"; //设置文件保存目录 注意包含/<br />$type = array(<br /> "jpg",<br /> "gif",<br /> "bmp",<br /> "jpeg",<br /> "png"<br />); //设置允许上传文件的类型<br />$patch = "uploadfiles/"; //程序所在路径<br />print_r($_FILES);<br />//获取文件后缀名函数<br />function fileext($filename) {<br /> return substr(strrchr($filename, '.') , 1);<br />}<br />//获取文件后缀名函数<br />function fileext2($filename2) {<br /> return substr(strrchr($filename2, '.') , 1);<br />}<br />//获取文件后缀名函数<br />function fileext3($filename3) {<br /> return substr(strrchr($filename3, '.') , 1);<br />}<br />//生成随机文件名函数<br />function random($length) {<br /> $hash = 'java-';<br /> $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';<br /> $max = strlen($chars) - 1;<br /> mt_srand((double)microtime() * 1000000);<br /> for ($i = 0; $i < $length; $i++) {<br /> $hash.= $chars[mt_rand(0, $max) ];<br /> }<br /> return $hash;<br />}<br />$a = strtolower(fileext($_FILES['img1']['name']));<br />$b = strtolower(fileext2($_FILES['img2']['name']));<br />$c = strtolower(fileext3($_FILES['img3']['name']));<br />//判断文件类型<br />if (!in_array(strtolower(fileext($_FILES['img1']['name'])) , $type)) {<br /> $text = implode(",", $type);<br /> echo "您只能上传以下类型文件: ", $text, "<br>";<br />}<br />//生成目标文件的文件名<br />else {<br /> $filename = explode(".", $_FILES['img1']['name']);<br /> $filename2 = explode(".", $_FILES['img2']['name']);<br /> $filename3 = explode(".", $_FILES['img3']['name']);<br /> do {<br /> $filename[0] = random(10); //设置随机数长度<br /> $name = implode(".", $filename);<br /> //$name1=$name.".Mcncc";<br /> $uploadfile = $uploaddir . $name;<br /> $filename2[0] = random(10); //设置随机数长度<br /> $name2 = implode(".", $filename2);<br /> //$name1=$name.".Mcncc";<br /> $uploadfile2 = $uploaddir . $name2;<br /> $filename3[0] = random(10); //设置随机数长度<br /> $name3 = implode(".", $filename3);<br /> //$name1=$name.".Mcncc";<br /> $uploadfile3 = $uploaddir . $name3;<br /> } while (file_exists($uploadfile));<br /><br /> if (move_uploaded_file($_FILES['img1']['tmp_name'], $uploadfile)) {<br /> //if(is_uploaded_file($_FILES['file']['tmp_name'])){<br /> //输出图片预览<br /> //echo "<center>您的文件已经上传完毕 上传图片预览: </center><br><center><img src='$uploadfile'></center>";<br /> //echo"<br><center><a href='javascript:history.go(-1)'>继续上传</a></center>";<br /> //}<br /> //else{<br /> //echo "上传失败!";<br /> <br /> }<br /> if (move_uploaded_file($_FILES['img2']['tmp_name'], $uploadfile2)) {<br /> //if(is_uploaded_file($_FILES['file']['tmp_name'])){<br /> //输出图片预览<br /> //echo "<center>您的文件已经上传完毕 上传图片预览: </center><br><center><img src='$uploadfile'></center>";<br /> //echo"<br><center><a href='javascript:history.go(-1)'>继续上传</a></center>";<br /> //}<br /> //else{<br /> //echo "上传失败!";<br /> <br /> }<br /> if (move_uploaded_file($_FILES['img3']['tmp_name'], $uploadfile3)) {<br /> //if(is_uploaded_file($_FILES['file']['tmp_name'])){<br /> //输出图片预览<br /> //echo "<center>您的文件已经上传完毕 上传图片预览: </center><br><center><img src='$uploadfile'></center>";<br /> //echo"<br><center><a href='javascript:history.go(-1)'>继续上传</a></center>";<br /> //}<br /> //else{<br /> //echo "上传失败!";<br /> <br /> }<br />}<br />$SourceFileName = $uploadfile;<br />$SourceFileName2 = $uploadfile2;<br />$SourceFileName3 = $uploadfile3;<br />?> <br /><br />