I have a form which uploads an image and works fine. Now, I want to have a way to change the image format on-the-fly and have added radio buttons to the form, but I am having trouble getting the data into the form. It part, the image input is:
My main question is to do with switch, which I have used only through cut-and-paste in the past. It was working until I added the elseif part of the conditional and now gives an "unexpected T_SWITCH" error. Can anyone advise on how to use switch properly to do what I need or am I going about it all wrong?
Don
Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases
Code:
if ($source = $_FILES["Image"]["tmp_name"]) {
if (file_exists($source)) {
$size = @GetImageSize($source);
$type = "";
if ($size[0] < 0 || $size[1] < 0) {
echo "Bad image format!";
} elseif switch ($_POST("ChangeFormat")) {
case 1:
$type = "gif";
break;
case 2:
$type = "jpeg";
break;
case 3:
$type = "png";
break;
} else switch ($size[2]) {
case 1:
$type = "gif";
break;
case 2:
$type = "jpeg";
break;
case 3:
$type = "png";
break;
default:
echo "Only JPG, GIF or PNG format images may be used";
}
// some GD image formatting function are were
}
}
My main question is to do with switch, which I have used only through cut-and-paste in the past. It was working until I added the elseif part of the conditional and now gives an "unexpected T_SWITCH" error. Can anyone advise on how to use switch properly to do what I need or am I going about it all wrong?
Don
Don
Experienced in HTML, Perl, PHP, VBScript, PWS, IIS and Apache and MS-Access, MS-SQL, MySQL databases