It’s a VERY simple php gallery. You could develop it in any direction. This one only supports jpg, but that could be augmented as well.
Here’s what it does:
Allows the user to choose an image and enter a title (or caption).
Uploads the image to a folder on the server.
Creates a thumbnail
Enters the filename and caption in a MySQL database.
Add an event handler for Form Closing and use this code. This is a really simple solution.
[c language=”#”]
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("Are you sure?", "Close application", MessageBoxButtons.YesNo) == DialogResult.Yes)
e.Cancel = false;
else
e.Cancel = true;
}
[/c]
Sometimes you need to check if a number is even or odd. A simple way to do this is using the modulus operator (the %-sign). It will calculate and return the remainder when dividing a value with another value.
So how do you use that to find out if a number is even or odd?
//validate email and name variables
if (!filter_var($email, FILTER_VALIDATE_EMAIL))
{
echo ‘not a valid e-mail adress’;
die();
}
if (preg_match(‘/[^a-z åäöÅÄÖüÜ _-]/i’, $name))
{
echo ‘not a valid name format’;
die();
}
//send the email
$send = mail($to, $subject, $message, $headers);
if ($send)
echo ’email sent’;
else
echo ‘something went wrong, email not sent’;
}
?>
Principle 1.
Always have a clear image of what you want to do BEFORE you start writing your code. Then break it down in logical instructions – making an algorithm. An algorithm is a step by step instruction on how to solve a specific problem. You might think of it as a recipe. If you want to bake bread – you don’t just start shoving any eatable stuff you find into the oven without a plan. First you decide what kind of bread you want to make, then you find out what ingredients is needed, how much and in what order they are added.
So basically – if you can’t solve the problem with logic you can’t solve it with code.
Here’s another way to do it. This example takes a number as a parameter instead of using the value of the element. A bit more compact code and it might be more flexible.
And here’s an even more flexible version. In this example you can pass the id of the element you want to hide as a second argument to the function. This way you can use the same function to toggle the visibility of many different elements.