语法错误Php(for-loop)

时间:2012-03-09 00:05:41

标签: php image loops for-loop syntax-error

这是搞乱php的唯一代码,我删除它并恢复完美,所以我猜这个循环语句中的内容是错误的;有谁可以看到什么错了?

下面假设搜索文件夹并查看图像是否已经在该文件夹中,如果是这样,每次将$ i换成+1($ i ++),然后再次检查最多30个数字。

知道我怎么能做到这一点? 我得到错误:

"HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while     the server was attempting to fulfill the request"

所以必须在代码中未正确配置

-Php循环代码

<?php

define ("MAX_SIZE","100"); 


 function getExtension($str) {
     $i = strrpos($str,".");
     if (!$i) { return ""; }
     $l = strlen($str) - $i;
     $ext = substr($str,$i+1,$l);
     return $ext;
 }


 $errors=0;
 if(isset($_POST['Submit'])) 
 {

$image=$_FILES['image']['name'];

if ($image) 
{

    $filename = stripslashes($_FILES['image']['name']);

    $extension = getExtension($filename);
    $extension = strtolower($extension);


 if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") &&     ($extension != "gif")) 
    {

//print error message

echo "";

        $errors=1;
    }
    else
    {

$size=filesize(['image']['tmp_name']);

if ($size > MAX_SIZE*1024)
{
echo "";

$errors=1;
}

 $image_name=time().'.'.$extension;



//Error Occurs Below
for($i=0; $i<30; $i++)
{
$relativePath="members/image/corey/"."photo".$i;
if(!file_exists($relativePath)) {
    continue;
}
    else
{
    $newNumber=$i;
    break;
}
}
$fileName=$_FILES["name"]."$newNumber";
$relativePath="members/image/corey/".$filename.'.'.$extension;
move_uploaded_file($image, $relativePath);

//Error Occurs Above
?>

-Buttons

    <form name="newad" method="post" enctype="multipart/form-data"  action="">
  <table>
  <tr><td><table>
    <tr>
      <td><input type="file" name="image" /></td>
    </tr>
    <tr>
      <td><input name="Submit" id="upload" type="submit" value="Upload image" onclick"load_images()" /></td>
    </tr>
  </table></td></tr>
  </table>      
</form>
</div>

4 个答案:

答案 0 :(得分:2)

您错过了结束“}”以匹配for循环的开头。

答案 1 :(得分:1)

你似乎至少错过了“for”循环的右括号。

答案 2 :(得分:1)

在那个片段中,你错过了一个结束}

答案 3 :(得分:1)

$["FILES"]["name"]?你错过了变量名。它应该是$_FILES['file']['name']

的内容

此外,move_uploaded_file有两个参数:源和目标。类似的东西:

move_uploaded_file($_FILES['file']['temp_name'], $relativePath);