kan ikke få mit foto vist?
Jeg kan ikke få min kode til og vise mit foto efter jeg har uploade det?? 60 point til den der er kan finde det for mig. :-)<form action="index.php" method="post" enctype="multipart/form-data">
<input type="file" name="fil"/>
<input type="submit" name="submit" value="upload" />
</form>
<?php
#file-field name
$file_field_name ="fil";
#submit-field name
$submit_field_name ="submit";
#allowed file-types
$allow_types =array("jpg","gif","png");
#directory where files will be uploaded to
$upload_dir ="images/";
#check if submit-button is clicked
if (isset($_POST [$submit_field_name])){
#check if there is a file
if (is_uploaded_file ($_FILES[$file_field_name]['tmp_name'])){
#get file extension
$file_ext = strtolower (pathinfo($_FILES[$file_field_name]['name'], PATHINFO_EXTENSION));
#check if file extension is alllowed
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']))){
echo "file is uploaded";
}else{
echo "error occured while moving the file";
};
}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";
};
};
?>
<?php
# Function to open any kkind of image
function open_image ($file) {
# JPEG:
$im = @imagecreatefromjpeg ($file);
if ($im !== false) {return $im;};
#gif:
$im = @imagecreatefromgif ($file);
if ($im !== false) {return $im;};
#png
$im = @imagecreatefrompng ($file);
if ($im !== false) {return $im;};
#gd file:
$im = @imagecreatefromgd ($file);
if ($im !== false) {return $im;};
#gd2
$im = @imagecreatefromgd2 ($file);
if ($im !== false) {return $im;};
#wbmp
$im = @imagecreatefromwbmp ($file);
if ($im !== false) {return $im;};
#xbm
$im = @imagecreatefromxbm ($file);
if ($im !== false) {return $im;};
#xpm
$im = @imagecreatefromxpm ($file);
if ($im !== false) {return $im;};
#try and load from string:
$im = @imagecreatefromstring (file_get_contents ($file));
if ($im !== false) {return $im;};
return false;
};
$image_path = "images/test.jpg";
$image_path_new = "images/temp.jpg";
$image = open_image($image_path);
if($image === false){
#Image can not be opened
echo "ikke gyldigt fil format. Kun jpg er tilladt";
}else{
# Original file size
$width = imagesx ($image);
$height = imagesy ($image);
#new file size
$width_new =150;
$height_new = $height * ($width_new / $width);
# resize / resample the imge
$image_resized = imagecreatetruecolor ($width_new, $height_new);
imagecopyresampled ($image_resized, $image, 0, 0, 0, 0, $width_new, $height_new, $width, $height);
#check if the image have been resized
if (!isset ($image_resized)){
$image_resized = $image;
};
$white = imagecolorallocate ($image_resized, 255, 255, 255);
imagestring ($image_resized, 5, 5, 5, "Denne tekst bliver sat på det nue foto", $white);
#SAVE the image
imagejpeg($image_resized, $image_path_new);
#display resized image
echo "New image:<br /><img src=\"".$image_path_new."\"><br />";
# display original image
echo "original image:<br /><img src=\"".$image_path."\">";
};
?>