DROP-DOWN MENU

What’s wrong with my code. It display the followin error message in the drop-down field:

Fatal error: Call to undefined function option_selected() in PHP in C:\xampp\htdocs\imageconcert/index.php on line 27

Here’s the code:

<?php if (isset($_GET["target"])) { function option_selected($target, $value) { $v=$_POST[$target]; if ($v == $target) { $selected="selected"; } echo $selected; } } ?>

Ezen az oldalon JPEG, PNG, BMP vagy GIF fájlt tudsz konverálni!

Forrás fájl (jpeg,png,bmp vagy gif, max. 2MB):

Célfájl formátuma <?php echo option_selected("target", "JPEG"); ?>> JPEG <?php echo option_selected("target", "JPE"); ?>> JPG <?php echo option_selected("target", "BMP"); ?>> BMP <?php echo option_selected("target", "GIF"); ?>> GIF <?php echo option_selected("target", "PNG"); ?>> PNG

Try changing “selected” to “target” you have not used "selected anywhere else as an identifier.

Unfortunately it didn’t help, the error message is still there. Any other idea?

What are you trying to do with this script? It’s not clear to me.

Later I’ll convert the uploaded jpg, bmp, png image to the format chosen in the drop-down menu.

You were trying to hard! No PHP needed to do this…

[php]

Ezen az oldalon JPEG, PNG, BMP vagy GIF fájlt tudsz konverálni!

Forrás fájl (jpeg,png,bmp vagy gif, max. 2MB):

Célfájl formátuma JPEG JPG BMP GIF PNG

[/php]

But in the function.php file how can I refer to the selection in the drop-down menu?

[php]$_POST[‘target’] or $_REQUEST[‘target’][/php]

But later, when I chose the type of the target file, how can I tell to PHP which option I selected in the drop-down menu?

Use either of these global variables to access whatever was chosen in the dropdown.

Those two variable passes are the Value fields of the options you selected.

put this as the only thing in the function.php file and you will see what i mean.

[php]<?php
echo $_POST[‘target’]."
";
echo $_REQUEST[‘target’];
?>[/php]

I want to convert an uploaded JPG into PNG. I want to store the new file in the uploads/ directory
$ext is the extension of the uploaded file. $target_path is the uploads/ directory. How should I change the following code?

[php]
if ($ext=‘jpg’ or $ext=‘jpeg’)

{
switch ($target)
{}
case “PNG”;
$image = imagecreatefromjpeg($path);
imagepng($image, ‘.basename’ . ‘png’, 100);
move_uploaded_file($image,$target_path);
break;
}
}
[/php]

I want to convert an uploaded JPG into PNG. I want to store the new file in the uploads/ directory
$ext is the extension of the uploaded file. $target_path is the uploads/ directory. How should I change the following code?
[php]
if ($ext=‘jpg’ or $ext=‘jpeg’)

{
switch ($target)
{
case “PNG”;
$image = imagecreatefromjpeg($path);
imagepng($image, ‘.basename’ . ‘png’, 100);
move_uploaded_file($image,$target_path);
break;
}
} [/php]

I also got this error:

Warning: imagepng() [function.imagepng]: gd-png error: compression level must be 0 through 9 in C:\xampp\htdocs\imageconvert\function.php on line 65

Go here for proper usage of imagepng http://php.net/manual/en/function.imagepng.php
Go here for a tutorial on how to upload files to a directory http://www.w3schools.com/php/php_file_upload.asp

You need to do more research before you post with I need help… We are here to help but we are not here to write your script for you. So far you have asked about every step and we have tried to help but these questions my be better in the beginners forums.

Sponsor our Newsletter | Privacy Policy | Terms of Service