Jeg uploader et gif billede, som jeg forventer at få ud i gif.
KOMPLET SCRIPT:
retvirksomhed.php
<?php
if(isset($_POST['update']) && is_numeric($_POST['id']))
{
include("../connect.php");
//SETTINGS
$logoname = $id . '.'; // hvad skal (thumb) logo ændres til
$uploadDir = '../update/logo/'; //Bibliotek, hvor filer uploades til - husk chmod 777
$allowedFileTypes = array('jpg','gif','png'); //Hvilke filer vil vi acceptere bliver uploadet?
//THUMBS SETTINGS
$thumbDir = '../update/thumbs/'; //Bibliotek, hvor thumbs gemmes - husk chmod 777
$thumbPrefix = $id . ' thumb_'; //Hvad skal tilføjes til originalt filnavn? //bruges ikke p.t.(mmk)
$thumbHeight = 100; //Thumb højde
$thumbWidth = 200; //Thumb bredde
$thumbQuality = 90; //Kvalitet af thumb, kan være fra 0 - dårligt til 100 - bedst
//Funktioner som bruges:
function getExtension($filename){
return strtolower( pathinfo( $filename, PATHINFO_EXTENSION ) );
}
function resize( $filename, $newfilename, $maxw, $maxh, $quality=85 )
{
$extension = getExtension($filename);
switch($extension)
{
case 'jpeg':
case 'jpe':
case 'jpg':
$srcim = imagecreatefromjpeg( $filename );
break;
case 'gif':
$srcim = imagecreatefromgif( $filename );
break;
case 'png':
$srcim = imagecreatefrompng( $filename );
break;
default:
return false;
}
$ow = imagesx( $srcim );
$oh = imagesy( $srcim );
$wscale = $maxw / $ow;
$hscale = $maxh / $oh;
$scale = min( $hscale, $wscale );
$nw = round( $ow * $scale, 0 );
$nh = round( $oh * $scale, 0 );
$dstim = imagecreatetruecolor( $nw, $nh );
imagecopyresampled( $dstim, $srcim, 0, 0, 0, 0, $nw, $nh, $ow, $oh );
switch($extension)
{
case 'jpeg':
case 'jpe':
case 'jpg':
imagejpeg( $dstim, $newfilename . $extension, $quality );
break;
case 'gif':
imagegif( $dstim, $newfilename . $extension );
break;
case 'png':
$png_q = floor( abs( $quality / 10 - 9.9 ) );
imagepng( $dstim, $newfilename . $extension, $png_q );
break;
default:
return false;
}
imagedestroy( $dstim );
imagedestroy( $srcim );
return file_exists($newfilename . $extension);
}
//Er der trykket på Upload file knappen?
if(isset($_POST['update']))
{
$id = intval($_POST['id']);
//$navn = mysql_real_escape_string($_POST['navn']);
//$adresse = mysql_real_escape_string($_POST['adresse']);
//$postnr = mysql_real_escape_string($_POST['postnr']);
//$by = mysql_real_escape_string($_POST['by']);
$telefon1 = mysql_real_escape_string($_POST['telefon1']);
$telefon2 = mysql_real_escape_string($_POST['telefon2']);
$fax = mysql_real_escape_string($_POST['fax']);
$email = mysql_real_escape_string($_POST['email']);
$web = mysql_real_escape_string($_POST['web']);
$region = mysql_real_escape_string($_POST['region']);
$cvr = mysql_real_escape_string($_POST['cvr']);
$branche = mysql_real_escape_string($_POST['branche']);
$logo = mysql_real_escape_string($_POST['logo']);
$antalmedarbejder = mysql_real_escape_string($_POST['antalmedarbejder']);
$virksomhedstype = mysql_real_escape_string($_POST['virksomhedstype']);
$stoettevis = mysql_real_escape_string($_POST['stoettbevis']);
mysql_query("UPDATE kopi_virksomheder SET
telefon1 = '".$telefon1."',
telefon2 = '".$telefon2."',
fax = '".$fax."',
email = '".$email."',
web = '".$web."',
region = '".$region."',
cvr = '".$cvr."',
branche = '".$branche."',
antalmedarbejder = '".$antalmedarbejder."',
virksomhedstype = '".$virksomhedstype."',
stoettebevis = '".$stoettebevis."'
WHERE id = '".$id."' LIMIT 1") or die(mysql_error());
if(mysql_affected_rows() >= 1)
{
header('Location: forside.php?virksomhedsid=' . $id);
exit();
}
else
{
$error = 'Opdateringen fejlede, kontakt venligst xxxxx Sekretariatet.';
}
//Har vi en fil?
if(is_uploaded_file($_FILES['myFile']['tmp_name']))
{
//Filendelse
$extension = getExtension($_FILES['myFile']['name']);
//Er filen en af de filer vi gerne vil have?
if(in_array($extension,$allowedFileTypes))
{
//Vi flytter filen fra tmp til vores UPLOADDIR
if(move_uploaded_file($_FILES['myFile']['tmp_name'],$uploadDir . basename($_FILES['myFile']['name'])))
{
//resizer
if(resize($uploadDir . basename($_FILES['myFile']['name']), $thumbDir . $logoname , $thumbWidth, $thumbHeight, $thumbQuality)){
$logoname = $logoname . $extension;
mysql_query("UPDATE kopi_virksomheder SET logo = '".$logoname."' WHERE id = '".$id."' ") or die(mysql_error());
header('Location: forside.php?virksomhedsid=' . $id);
exit();
}else
{
echo '<h3 style="color:red;">File ('.basename($_FILES['myFile']['name']).') Logo er for lille, minimum 100pX100p</h3>';
echo '<br><br>';
echo '<span class="blue"><a href="retvirksomhed.php?virksomhedsid='.$id.'">tilbage</a></span>';
echo ' <img src="../images/linkspacer.gif" width="21" height="10">';
}
}
else
{
echo '<h3 style="color:red;">Fejl - logoet kunne ikke uploades: '.basename($_FILES['myFile']['name']).'</h3>';
echo '<br><br>';
echo '<span class="blue"><a href="retvirksomhed.php?virksomhedsid='.$id.'">tilbage</a></span>';
echo ' <img src="../images/linkspacer.gif" width="21" height="10">';
}
}
else
{
echo '<img src="
http://xxxxx.dk/images/fejl.jpg"> <h3 style="color:red;">Forkert filtype, tilladte filetyper er: ('.implode(', ',$allowedFileTypes).')</h3>';
echo '<br><br>';
echo '<span class="blue"><a href="retvirksomhed.php?virksomhedsid='.$id.'">tilbage</a></span>';
echo '<img src="../images/linkspacer.gif" width="21" height="10">';
}
}
else
{
//echo '<h3 style="color:red;">No file selected<h3>';
}
}
}
?>
<html>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
loadImage1 = new Image();
loadImage1.src = "
http://xxxxx.dk/images/q3.jpg";staticImage1 = new Image();
staticImage1.src = "
http://xxxxx.dk/images/q2.jpg";// End -->
</script>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
loadImage2 = new Image();
loadImage2.src = "
http://xxxxx.dk/images/q3.jpg";staticImage2 = new Image();
staticImage2.src = "
http://xxxxx.dk/images/q2.jpg";// End -->
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<LINK href="../default.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript">
function getBynavn()
{
new Ajax.Request( 'ajax.php', {
method: 'get',
parameters: { zipcode: $F('postnr') },
onComplete: function(transport)
{
switch(transport.responseText)
{
default:
$('bynavn').update(transport.responseText);
}
}
});
}
</script>
</head>
<body class = "xxxxx_body">
<?
require_once("../connect.php");
if(is_numeric($_GET['virksomhedsid']))
{
$id = intval($_GET['virksomhedsid']);
$result = mysql_query("SELECT p.navn AS pNavn, v.* FROM kopi_virksomheder AS v INNER JOIN postnumre AS p ON v.postnr = p.nummer WHERE id = '".$id."' LIMIT 1") or die(mysql_error());
if(mysql_num_rows($result) == 1)
{
$row = mysql_fetch_array($result);
?>
<p><span class="blue2">Ret virksomheds Info</span></p>
<form action="retvirksomhed.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $row['id']?>" />
<table border="0">
<tr><td><span class="blue">Virksomhed:</td><td class="bottomtext"><?php echo $row['navn']?></td></tr>
<tr><td><br></td></tr>
<tr><td><span class="blue">Telefon:</td><td class="bottomtext"><input type="text" maxlength="8" name="telefon1" value="<?php echo ($row['telefon1'] > 0)?$row['telefon1']:'';?>" /></td></tr>
<tr><td><span class="blue">Telefon2:</td><td class="bottomtext"><input type="text" maxlength="8" name="telefon2" value="<?php echo ($row['telefon2'] > 0)?$row['telefon2']:'';?>" /></td></tr>
<tr><td><span class="blue">Fax:</td><td class="bottomtext"><input type="text" maxlength="8" name="fax" value="<?php echo ($row['fax'] > 0)?$row['fax']:'';?>" /></td></tr>
<tr><td><span class="blue">E-mail:</td><td class="bottomtext"><input type="text" name="email" value="<?php echo $row['email']?>" /></td></tr>
<tr><td><span class="blue">Web:</td><td class="bottomtext"><input type="text" name="web" value="<?php echo $row['web']?>" /></td></tr>
<tr><td><span class="blue">Region:</td><td class="bottomtext"><?=regionOptions($row['region']);?></td></tr>
<tr><td><span class="blue">CVR:</td><td class="bottomtext"><input type="text" name="cvr" value="<?php echo ($row['cvr'] > 0)?$row['cvr']:'';?>" /></td></tr>
<tr><td> </td></tr>
<tr><td><span class="blue">Branche:</td><td class="bottomtext"><?=brancheOptions($row['branche']);?></td></tr>
<tr><td><span class="blue">Logo:</td><td><input type="file" name="myFile"></td><td><span onmouseover="image2.src=loadImage2.src;" onmouseout="image2.src=staticImage2.src;">
<img name="image2" src="
http://xxxxx.dk/images/q2.jpg" onclick="window.open('/update/vejledninger/ret-virksomhed-logo.html','mitvindue', 'width=250,height=300');return false;" border=0></span></td></tr>
<tr><td><span class="blue">Antal Medarbejder:</td><td class="bottomtext"><input type="text" name="antalmedarbejder" value="<?php echo $row['antalmedarbejder']?>" /></td></tr>
<tr><td><span class="blue">Virksomhedstype:</td><td class="bottomtext"><?=virksomhedstypeOptions($row['virksomhedstype']);?></td></tr>
<tr><td><span class="blue">Ønsker <br> nyt Støttebevis: </td><td class="bottomtext"><?=radiobutton('stoettebevis',$row['stoettebevis']);?>
<span onmouseover="image1.src=loadImage1.src;" onmouseout="image1.src=staticImage1.src;">
<img name="image1" src="
http://xxxxx.dk/images/q2.jpg" onclick="window.open('/update/vejledninger/ret-virksomhed-stottebevis.html','mitvindue', 'width=250,height=300');return false;" border=0></span>
</td></tr>
<tr>
<td><br>
</td>
</tr>
</table>
<input type="submit" value="Opdater virksomhed" name="update" />
</form>
<br><br>
<span class="blue"><a href="forside.php?virksomhedsid=<?=$id;?>">tilbage</a></span>
<img src="../images/linkspacer.gif" width="21" height="10">
<?
}
else
{
?>
<p><span class="blue2">Fejl, virksomhed ikke fundet!</span></p>
<?
}
}
?>
</body>
</html>