2 - PHP时循环中断

时间:2011-05-06 05:32:56

标签: php

这是一个非常简单的脚本,但是当插槽正好为2时它会中断,对于其他情况,脚本运行正常 我找不到错误,请帮忙!

function main()
{
 $slots=$_POST['counter']; //number of slots
 include 'config.php';
 for ($num = 1; $num <= $slots; $num++) //$num starts from 1, not 0
 {
  if (($_FILES["myfile$num"]['type']=='image/jpeg'))
  {
   move_uploaded_file($_FILES["myfile$num"]['tmp_name'],$albumDir.'\\'.$_FILES["myfile$num"]['name']);
   copy($albumDir.'\\'.$_FILES["myfile$num"]['name'], $albumDir.'_thumb\\'.$_FILES["myfile$num"]['name']);
   resize($_FILES["myfile$num"]['name']);
  }
  else if($_FILES["myfile$num"]['name']!='')
    echo 'Image should be in JPEG/JPG format, and size should not exceed 1 MB';
 }
}

3 个答案:

答案 0 :(得分:1)

检查$ _POST ['counter']值是否设置== 2;然后u proccedd ...

    $slots=count($_POST['name']);
 //number of slots
 include 'config.php';
 for ($num = 1; $num <= $slots; $num++) //$num starts from 1, not 0

or
  for ($num = 1; $num < $slots+1; $num++)
 {
         //your code..
}

答案 1 :(得分:0)

从0开始$ num

for ($num = 0; $num <= $slots; $num++) 

答案 2 :(得分:0)

你的代码很好。可能会发生以下情况:

  • 您的计数器var与上传文件的实际数量不同

  • 您的文件名并不是您想要阅读的文件名。

希望这会有所帮助。干杯