For some reason this is just looping infernally. I'm sure its something really stupid but it's getting the better of me today.
SQL query/method
public function getimages()
{
if ($results = $this->database->query("SELECT * FROM `products` WHERE processed!='1'"))
{
return $results->fetch_array(MYSQLI_ASSOC);
}
}
process_image.php
<?php
$products = products::getinstance();
$url = "/images/products/";
//set $row with the results from get images
while ($row = $products->getimages())
{
$temp = tempnam("tmp/", "IMG_");
$handle = fopen($temp, "w+");
fwrite($handle, $row['front_img']);
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$thumb = $url.$image->create_image('thumb');
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$img = $url.$image->create_image('normal');
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$detail = $url.$image->create_image('detail');
if (!$products->saveimages($row['id'], $thumb, $img, $detail, 'front'))
{
echo 'fail - id: '.$row['id'].'- front';
}
fclose($handle); // this removes the file
unset($thumb, $img, $detail);
//if there is a back image process it
if ($row['back_img'])
{
$temp = tempnam("tmp/", "IMG_");
$handle = fopen($temp, "w+");
fwrite($handle, $row['back_img']);
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$thumb = $url.$image->create_image('thumb');
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$img = $url.$image->create_image('normal');
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$detail = $url.$image->create_image('detail');
if (!$products->saveimages($row['id'], $thumb, $img, $detail, 'back'))
{
echo 'fail - id: '.$row['id'].'- back';;
}
fclose($handle); // this removes the file
unset($thumb, $img, $detail);
}
//if there is a detail 1 image process it
if ($row['detail_img1'])
{
$temp = tempnam("tmp/", "IMG_");
$handle = fopen($temp, "w+");
fwrite($handle, $row['detail_img1']);
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$thumb = $url.$image->create_image('thumb');
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$img = $url.$image->create_image('normal');
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$detail = $url.$image->create_image('detail');
if (!$products->saveimages($row['id'], $thumb, $img, $detail, 'detail1'))
{
echo 'fail - id: '.$row['id'].'- detail';
}
fclose($handle); // this removes the file
unset($thumb, $img, $detail);
}
//if there is a detail 2 image process it
if ($row['detail_img2'])
{
$temp = tempnam("tmp/", "IMG_");
$handle = fopen($temp, "w+");
fwrite($handle, $row['detail_img2']);
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$thumb = $url.$image->create_image('thumb');
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$img = $url.$image->create_image('normal');
$image = new image($temp, constants::UPLOADDIR_PRODUCTS);
$detail = $url.$image->create_image('detail');
if (!$products->saveimages($row['id'], $thumb, $img, $detail, 'detail2'))
{
echo 'fail - id: '.$row['id'].'- detail 2';
}
fclose($handle); // this removes the file
unset($thumb, $img, $detail);
}
}
?>
Note: There is only 1 row in the database