New development, if its of any help....
If I open my jpg in Photoshop and resave it, it will upload but not output the image. (in other words, the script thinks no image has been uploaded and as such defaults the product to display no image) This will hold true for files over 1MB.
I did this with a picture from my SLR, from the camera the file was 2.3MB but out of photoshop with no editing, the file came to 3.3MB... Neither uploaded but the one from photoshop didn't make the error occur.
However, running the script multiple times and using an image straight from the SLR it will run the script but not upload. Which is where it confuses me.
As far as I can tell, this is the code to do with uploading the images and resizing them etc:
/*
Create a thumbnail of $srcFile and save it to $destFile.
The thumbnail will be $width pixels.
*/
function createThumbnail($srcFile, $destFile, $width, $quality = 75)
{
$thumbnail = '';
if (file_exists($srcFile) && isset($destFile))
{
$size = getimagesize($srcFile);
$w = number_format($width, 0, ',', '');
$h = number_format(($size[1] / $size[0]) * $width, 0, ',', '');
$thumbnail = copyImage($srcFile, $destFile, $w, $h, $quality);
}
// return the thumbnail file name on sucess or blank on fail
return basename($thumbnail);
}
/*
Copy an image to a destination file. The destination
image size will be $w X $h pixels
*/
function copyImage($srcFile, $destFile, $w, $h, $quality = 75)
{
$tmpSrc = pathinfo(strtolower($srcFile));
$tmpDest = pathinfo(strtolower($destFile));
$size = getimagesize($srcFile);
if ($tmpDest['extension'] == "gif" || $tmpDest['extension'] == "jpg")
{
$destFile = substr_replace($destFile, 'jpg', -3);
$dest = imagecreatetruecolor($w, $h);
imageantialias($dest, TRUE);
} elseif ($tmpDest['extension'] == "png") {
$dest = imagecreatetruecolor($w, $h);
imageantialias($dest, TRUE);
} else {
return false;
}
switch($size[2])
{
case 1: //GIF
$src = imagecreatefromgif($srcFile);
break;
case 2: //JPEG
$src = imagecreatefromjpeg($srcFile);
break;
case 3: //PNG
$src = imagecreatefrompng($srcFile);
break;
default:
return false;
break;
}
imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
switch($size[2])
{
case 1:
case 2:
imagejpeg($dest,$destFile, $quality);
break;
case 3:
imagepng($dest,$destFile);
}
return $destFile;
}
and
function uploadImage($inputName, $uploadDir)
{
$image = $_FILES[$inputName];
$imagePath = '';
// if a file is given
if (trim($image['tmp_name']) != '') {
// get the image extension
$ext = substr(strrchr($image['name'], "."), 1);
// generate a random new file name to avoid name conflict
$random_id_length = 10;
$rnd_id = crypt(uniqid(rand(),1));
$rnd_id = strip_tags(stripslashes($rnd_id));
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
$rnd_id = substr($rnd_id,0,$random_id_length);
$imagePath = "$rnd_id" . ".$ext";
// check the image width. if it exceed the maximum
// width we must resize it
$size = getimagesize($image['tmp_name']);
if ($size[0] > MAX_CATEGORY_IMAGE_WIDTH) {
$imagePath = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_CATEGORY_IMAGE_WIDTH);
} else {
// move the image to category image directory
// if fail set $imagePath to empty string
if (!move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath)) {
$imagePath = '';
}
}
}
return $imagePath;
}
Sorry if thats a lot of code to sift through, but its abit purplexing as to why lower sized files will work ok, yet its hit and miss when the file exceeds ~500kb...