This is the only code messing up the php, I removed it and it resumes perfecty, so I am guessing something within this loop statement is wrong; can someone please see whats wrong?
The below suppose to search the folder and see if the image is already within that folder, if so it chnges the $i by +1 each time ($i++) and then checks again with a max of 30 number.
Any idea how I can accomplish this?
Error I Get:
"HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request"
So must be something within the code not configured correctly
-Php Loop Code
<?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>
You’re missing a closing “}” to match the opening one for your
forloop.