PHP没选择图片 也会打印出选择图片

WBOY
Release: 2016-06-23 14:04:08
Original
965 people have browsed it

前台代码 浏览图片控件

while($row = mysql_fetch_array($result))  {echo'<form action="2jiyemianluoji.php" method="post" enctype="multipart/form-data"><div class="zidingyiwenben"> <textarea id="textarea" rows="1" cols="1" name="detail4" class="zz">'.$row['tupiandetail'].'</textarea> <input type="file" id="file" name="file"  class="yy"> </div>';for($i=1; $i<10; $i++){    $j=$i+1;	$k=$i+5;echo'<div>输入图片'.$j.'(大小394px*296px)</div><div class="zidingyiwenben"> <textarea id="textarea'.$i.'" rows="1" cols="1" name="detail'.$k.'" class="zz">'.$row['tupiandetail'.$i].'</textarea> <input type="file" id="file'.$i.'" name="file'.$i.'"  class="yy"> </div>';}<div><button type="submit" >保存</button></div></form>';  }
Copy after login


后台
  for($i=1;$i<10;$i++)  {	  $j=$i+1;	  $k=$i+5;  if ($_FILES["file'.$i.'"]["error"] > 0)  { echo'没有选择图片'.$j;  ${"iii".$i}=$_POST['detail'.$k];    }else  {   if (file_exists("images/" . $_FILES["file'.$i.'"]["name"]))      {      echo $_FILES["file'.$i.'"]["name"].'图片文件名'.$j.'已存在请换文件名';	    ${"iii".$i}='';      }    else      {		        move_uploaded_file($_FILES["file'.$i.'"]["tmp_name"],      "images/" . $_FILES["file'.$i.'"]["name"]);      echo "Stored in: " . "images/" . $_FILES["file'.$i.'"]["name"];	  ${"iii".$i}= 'images/'.$_FILES["file'.$i.'"]["name"];		  }  }      }
Copy after login


为什么我没有选择图片 不会输出没有选择图片


回复讨论(解决方案)

"file'.$i.'"
这种东西得不到你想要的结果,应该是
"file{$i}"

你先把这个改了再说吧

PHP变量分离不是都是用'.$i.'的么。。

我都把双引号改成单引号就解决了 

提交后 print_r($_FILES); 看看都是些什么

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template