Jeg bliver snart idiot
Håber virkelig en her inde vil hjælpe en "dum" programmør med at sætte disse to scrips sammen, som jeg ligger ind herunder... ingen spørgsmål helst, for aner ikke hvad det er min lærer vil hen med dette. jeg skal bare kunne oploade et billede og få det vist derefter. ingen database er med.<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Billedmanipulation</title>
</head>
<body>
<form action="index.php" method="POST" enctype="multipart/form-data">
<input type="file" name="fil" />
<input type="submit" name="submit" value="upload" />
</form>
<?php
//upload med regler
// File-field navn
$file_field_name = "fil";
// Submit -field navn
$submit_field_name = "submit";
//tillad fil-typer
$allow_types = array("jpg");
// Directory where files will be uploadet to.
$upload_dir = "images/";
//Check if submit-button is clicked
if(isset($_POST[$submit_field_name])){
//tjekker om det er en fil som skal uploades
if(is_uploaded_file($_FILES[$file_field_name]['tmp_name'])){
//fikser filens størrelse
$file_ext = strtolower(pathinfo($_FILES[$file_field_name]['name'], PATHINFO_EXTENSION));
//Check if file extension is allowed
if(in_array($file_ext, $allow_types)){
//move file to the upload directory
if(move_uploaded_file($_FILES[$file_field_name]['tmp_name'], $upload_dir.basename($_FILES[$file_field_name]['name']))){
open_image(basename($_FILES[$file_field_name]['name']));
}else{
echo "fejl";
};
}else{
//file type is not allowed
echo "file type is not allowed";
};
}else{
//if there is not a file
echo "Select a file for upload";
};
};
//her tjekker den om filerne kan åbnes i den str den er, ellers laver den str om så den passer til ens design.
function open_image ($file){
$im = @imagecreatefromjpeg($file);
if ($im !== false) {return $im;}
$im = @imagecreatefromgif($file);
if ($im !== false) {return $im;}
$im = @imagecreatefrompng($file);
if ($im !== false) {return $im;}
$im = @imagecreatefromgd($file);
if($im !== false) {return $im;}
$im = @imagecreatefromgd2($file);
if($im !== false) {return $im;}
$im = @imagecreatefromwbmp($file);
if($im !== false) {return $im;}
$im = @imagecreatefromxbm($file);
if($im !== false) {return $im;}
$im = @imagecreatefromxpm($file);
if($im !== false) {return $im;}
$im = @imagecreatefromstring(file_get_contents($file));
if($im !== false) {return $im;}
return false;
};
//dininere hvor filen ligger
$image_path = "images/".$file."";
$image_path_new = "temp.jpg";
$image = open_image($image_path);
if($image === false){
echo "Næ næ næ det må du ikke, KUN jpg kan bruges";
}else{
$width = imagesx($image);
$height = imagesy($image);
//udregner ny str
$width_new = 150;
$height_new = $height * ($width_new / $width);
$image_resized = imagecreatetruecolor($width_new,$height_new);
imagecopyresampled($image_resized,$image,0,0,0,0,$width_new,$height_new,$width,$height);
if(!isset($image_resized)){
$image_resized = $image;
};
//get the color for the watermark text
$white = imagecolorallocate($image_resized,255,255,255);
//Add watermark to the image
imagestring($image_resized, 5, 5, 5, "Maylind", $white);
imagejpeg($image_resized,$image_path_new);
echo "Behandlet billede: <img src='".$image_path_new."' />";
echo "<br /><br />";
echo "Orginale billede: <img src='".$image_path."' />";
};
?>
</body>
</html>