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>
500 (Internal Server Error) can be given for various reasons, one of them is that PHP exited with a fatal error. You find the PHP errors in your PHP error log if you configure it.
If you have configured the PHP error log and you don’t find anything related to the script in there, you need to check the server’s error log. It logs all 500 errors and gives you the reason.
You can even check the servers error log first, however the reason in there might seem very cryptic and only tells you (if you know how to read it) that it was a PHP error – which is better explained in the php error log.
If you don’t have access to your servers error log files, contact the technical support of your hoster.