Billede upload med scalering af billede
Hej igen.Jeg er stødt på endnu et problem. jeg har en hjemmeside hvor en maler skal kunne uploade sine billeder. dette virker perfekt, dog vil jeg gerne have dem scaleret ned i pixel. hvordan gør jeg nu det..
Koden til visning af billeder ser således ud:
<html>
<head>
<title>Velkommen til madebyjanfrydkjaer.dk</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style2.css" rel="stylesheet" type="text/css">
</head>
<div id="main">
<div id="banner"></div>
<div id="menu">
<?php include("menu.php"); ?>
</div>
<div id="center">
<?php
function get_files_from_dir($dirname)
{
$dirhandle = opendir($dirname);
while($file = readdir($dirhandle))
{
if ($file != "." && $file != "..")
{
if (is_file($dirname."/".$file))
{
$GLOBALS['files'][] = $dirname."/".$file;
}
else
{
get_files_from_dir($dirname."/".$file);
}
}
}
}
get_files_from_dir("upload/acryl");
get_files_from_dir("upload/tegning");
get_files_from_dir("upload/tryk");
get_files_from_dir("upload/akvarel");
foreach($GLOBALS['files'] as $file)
{
echo "<a href='$file' target='_blank'>" . "<br /><img src='$file'/></a><br />";
}
?>
</div>
</div>
</body>
</html>
Koden til upload af billeder ser således ud:
<?php
// Connects to your Database
mysql_connect("127.0.0.1", "root", "1234") or die(mysql_error());
mysql_select_db("madebyjanfrydkja") or die(mysql_error());
//checks cookies to make sure they are logged in
if(isset($_COOKIE['ID_my_site']))
{
$username = $_COOKIE['ID_my_site'];
$pass = $_COOKIE['Key_my_site'];
$check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error());
while($info = mysql_fetch_array( $check ))
{
//if the cookie has the wrong password, they are taken to the login page
if ($pass != $info['password'])
{ header("Location: login.php");
}
//otherwise they are shown the admin area
else
{
}
}
}
else
//if the cookie does not exist, they are taken to the login screen
{
header("Location: login.php");
}
?>
<html>
<head>
<title>Velkommen til madebyjanfrydkjaer.dk</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style2.css" rel="stylesheet" type="text/css">
</head>
<div id="main">
<div id="banner"></div>
<div id="menu">
<?php include("menu.php"); ?>
</div>
<div id="center">
<p> </p>
<p>Du er nu logget ind som <?php echo $username; ?></p>
<div id="acryl">
<h3>Opload billede til acryl</h3>
<form action="upload_acryl.php" method="post" enctype="multipart/form-data">
Vælg en fil her:
<br>
<input type="file" name="file" id="file" />
<br>
<input type="submit" name="submit" value="Upload" />
</form>
</div>
<div id="tegning">
<h3>Opload billede til tegning</h3>
<form action="upload_tegning.php" method="post" enctype="multipart/form-data">
Vælg en fil her:
<br>
<input type="file" name="file" id="file" />
<br>
<input type="submit" name="submit" value="Upload" />
</form>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<div id="akvarel">
<h3>Opload billede til akvarel</h3>
<form action="upload_akvarel.php" method="post" enctype="multipart/form-data">
Vælg en fil her:
<br>
<input type="file" name="file" id="file" />
<br>
<input type="submit" name="submit" value="Upload" />
</form>
</div>
<div id="tryk">
<h3>Opload billede til tryk</h3>
<form action="upload_tryk.php" method="post" enctype="multipart/form-data">
Vælg en fil her:
<br>
<input type="file" name="file" id="file" />
<br>
<input type="submit" name="submit" value="Upload" />
</form>
</div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<a href=logout.php>Logout</a>
<div id="add">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Brugernavn:
<input type="text" name="username" maxlength="60">
Adgangskode:
<input type="password" name="pass" maxlength="10">
Bekræft:
<input type="password" name="pass2" maxlength="10">
<input type="submit" name="submit" value="Register">
</form>
<?php
// Connects to your Database
mysql_connect("127.0.0.1", "root", "1234") or die(mysql_error());
mysql_select_db("login") or die(mysql_error());
//This code runs if the form has been submitted
if (isset($_POST['submit'])) {
//This makes sure they did not leave any fields blank
if (!$_POST['username'] | !$_POST['pass'] | !$_POST['pass2'] ) {
die('Du har ikke udfyldt alle felter');
}
// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['username'] = addslashes($_POST['username']);
}
$usercheck = $_POST['username'];
$check = mysql_query("SELECT username FROM users WHERE username = '$usercheck'")
or die(mysql_error());
$check2 = mysql_num_rows($check);
//if the name exists it gives an error
if ($check2 != 0) {
die('Brugernavnet '.$_POST['username'].' er allerede i brug.');
}
// this makes sure both passwords entered match
if ($_POST['pass'] != $_POST['pass2']) {
die('Adgangskoden er ikke ens.
');
}
// here we encrypt the password and add slashes if needed
$_POST['pass'] = md5($_POST['pass']);
if (!get_magic_quotes_gpc()) {
$_POST['pass'] = addslashes($_POST['pass']);
$_POST['username'] = addslashes($_POST['username']);
}
// now we insert it into the database
$insert = "INSERT INTO users (username, password)
VALUES ('".$_POST['username']."', '".$_POST['pass']."')";
$add_member = mysql_query($insert);
}
else
{
?>
<?php
}
?>
</div>
</div>
</div>
</div>
</body>
</html>