PCHomepage
Programmer
A form is converting (if necessary), resizing and uploading an image and is working fine but the same form also has other fields that I need to be able to edit without re-uploading the image, such as captions and that sort of thing, but I can't seem to figure out how to make it work without overwriting. The code is straightforward so can anyone see what I've missed? I even tried adding a conditional that should keep whatever is there as-is but it shouldn't even get to it with no image:
PHP:
if ($source = $_FILES["FileUpload"]["tmp_name"]) {
if (file_exists($source)) {
$size = @GetImageSize($source);
$Types = array(1,2,3,6);
if (!in_array($size[2], $Types)) {
$imageupload->Image->Errors->AddError("<font color=\"red\">Only JPG, GIF, BMP or PNG format images may be used.</font>");
$imageupload_OnValidate = 0;
}
if ($size[0] < 0 || $size[1] < 0) {
$imageupload->Image->Errors->AddError("<font color=\"red\">Bad image format!</font>");
$imageupload_OnValidate = 0;
}
if (isset($_POST['ResetWidth'])) {
$Width = $_POST['ResetWidth'];
} else {
$Width = "";
}
$Sizes = imageNewsize($size[0], $size[1], $Width);
$NewImageHeight = $Sizes[0];
$NewImageWidth = $Sizes[1];
$FormatType = $size[2];
$NewFormat = str_replace("mime/","",$size['mime']);
if (isset($_POST['ThumbWidth'])) {
$ThumbWidth = $_POST['ThumbWidth'];
} else {
$ThumbWidth = 50;
}
if ($NewImageHeight > 0 && $NewImageWidth > 0) {
$imageupload->Image->SetValue(ConvertImage($source, $Width));
$imageupload->Thumbnail->SetValue(ConvertImage($source, $ThumbWidth));
$imageupload->ImageSize->SetValue(strlen(ConvertImage($source, $Width)));
$imageupload->ImageWidth->SetValue($NewImageWidth);
$imageupload->ImageHeight->SetValue($NewImageHeight);
$imageupload->ImageFormat->SetValue($NewFormat);
} else {
$imageupload->Image->SetValue($imageupload->ds-f("Image"));
$imageupload->Thumbnail->SetValue($imageupload->ds-f("Thumbnail"));
}
}
}