PHP plaatjes upload script -- aanpassen?
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
//Variables
$max = 180; //The width or height of the destination image
$dir = "../plaatjes/"; //The folder for the destionation image
$quality = 75; //The quality of the destination image
//Form to upload the pictures
if(!$upload)
{
echo("With this form you can upload your banner/image. The image has to be .jpg or .gif.<br />");
echo("Depending on the size, uploading your file can take a while. Please press the upload button only once!<br /><br />");
echo("<table>");
echo("<form action=\"picturesphp.php\" method=\"post\" enctype=\"multipart/form-data\">");
echo("<tr><td>File:</td><td><input type=\"file\" name=\"bestand\" /></td></tr>");
echo("<tr><td>File name (Your company name)</td><td><input type=\"text\" name=\"naam\" /></td><tr>");
echo("<tr><td></td><td><input type=\"submit\" name=\"upload\" value=\"upload\" ><input type=\"button\" value=\"Go back to form\" onClick=\"history.go(-1)\" ></td><tr></form></table>");
}
else
{
//Check if a file was selected
if(!$bestand)
{
echo("You did not select a file, please go back and select a file");
}
elseif(strlen($naam)==0)
{
echo("No file name, please go back and name your file");
}
//Check if the file-type is JPG
elseif(($_FILES['bestand']['type'] != "image/jpeg") && ($_FILES['bestand']['type'] != "image/pjpeg") && ($_FILES['bestand']['type'] != "image/gif"))
{
echo("You can only upload .gif or .jpg" );
echo($_FILES['bestand']['type']);
}
else
{
$temp_file = $_FILES['bestand']['tmp_name'];
$source = imagecreatefromjpeg($temp_file);
//retrieving the width and height of the file
$width = imageSX($source);
$height = imageSY($source);
//determining the ratio to calculate the new height
//calculating the new height
if($widht < $max && $height < $max)
{
$new_width = $width;
$new_height = $height;
}
else
{
if($width > $height)
{
$ratio = $width/$height;
$new_width = $max;
$new_height = $new_width/$ratio;
}
elseif($width < $height)
{
$ratio = $height/$width;
$new_height = $max;
$new_width = $new_height/$ratio;
}
else
{
$new_height = $max;
$new_width = $max;
}
}
//Create a new true color image with the new width and height
$destination = imagecreatetruecolor($new_width, $new_height) or die("Can't process picture");
//Copy and resize the existing file to the dimensions of the new file
imagecopyresampled($destination, $source, 0,0,0,0,$new_width, $new_height, $width, $height);
//writing the new file
ob_start();
ImageJPEG($destination, '', $quality);
$buffer = ob_get_contents();
ob_end_clean();
$filename = $dir.$naam.'.jpg';
if(is_file($filename))
{
if(!unlink($filename))
{
echo("File could not be removed");
}
}
$handle = fopen($filename, 'ab'); //write only in binair
if(fwrite($handle, $buffer))
{
echo("File has been uploaded succesfully<br /><br />");
echo("<tr><td></td><td><input type=\"button\" value=\"Go back to form\" onClick=\"history.go(-2)\" ></td></tr></form></table>");
}
else
{
echo("An error occured during uploading your file, please try again");
}
fclose($handle);
}
}
?>
//Variables
$max = 180; //The width or height of the destination image
$dir = "../plaatjes/"; //The folder for the destionation image
$quality = 75; //The quality of the destination image
//Form to upload the pictures
if(!$upload)
{
echo("With this form you can upload your banner/image. The image has to be .jpg or .gif.<br />");
echo("Depending on the size, uploading your file can take a while. Please press the upload button only once!<br /><br />");
echo("<table>");
echo("<form action=\"picturesphp.php\" method=\"post\" enctype=\"multipart/form-data\">");
echo("<tr><td>File:</td><td><input type=\"file\" name=\"bestand\" /></td></tr>");
echo("<tr><td>File name (Your company name)</td><td><input type=\"text\" name=\"naam\" /></td><tr>");
echo("<tr><td></td><td><input type=\"submit\" name=\"upload\" value=\"upload\" ><input type=\"button\" value=\"Go back to form\" onClick=\"history.go(-1)\" ></td><tr></form></table>");
}
else
{
//Check if a file was selected
if(!$bestand)
{
echo("You did not select a file, please go back and select a file");
}
elseif(strlen($naam)==0)
{
echo("No file name, please go back and name your file");
}
//Check if the file-type is JPG
elseif(($_FILES['bestand']['type'] != "image/jpeg") && ($_FILES['bestand']['type'] != "image/pjpeg") && ($_FILES['bestand']['type'] != "image/gif"))
{
echo("You can only upload .gif or .jpg" );
echo($_FILES['bestand']['type']);
}
else
{
$temp_file = $_FILES['bestand']['tmp_name'];
$source = imagecreatefromjpeg($temp_file);
//retrieving the width and height of the file
$width = imageSX($source);
$height = imageSY($source);
//determining the ratio to calculate the new height
//calculating the new height
if($widht < $max && $height < $max)
{
$new_width = $width;
$new_height = $height;
}
else
{
if($width > $height)
{
$ratio = $width/$height;
$new_width = $max;
$new_height = $new_width/$ratio;
}
elseif($width < $height)
{
$ratio = $height/$width;
$new_height = $max;
$new_width = $new_height/$ratio;
}
else
{
$new_height = $max;
$new_width = $max;
}
}
//Create a new true color image with the new width and height
$destination = imagecreatetruecolor($new_width, $new_height) or die("Can't process picture");
//Copy and resize the existing file to the dimensions of the new file
imagecopyresampled($destination, $source, 0,0,0,0,$new_width, $new_height, $width, $height);
//writing the new file
ob_start();
ImageJPEG($destination, '', $quality);
$buffer = ob_get_contents();
ob_end_clean();
$filename = $dir.$naam.'.jpg';
if(is_file($filename))
{
if(!unlink($filename))
{
echo("File could not be removed");
}
}
$handle = fopen($filename, 'ab'); //write only in binair
if(fwrite($handle, $buffer))
{
echo("File has been uploaded succesfully<br /><br />");
echo("<tr><td></td><td><input type=\"button\" value=\"Go back to form\" onClick=\"history.go(-2)\" ></td></tr></form></table>");
}
else
{
echo("An error occured during uploading your file, please try again");
}
fclose($handle);
}
}
?>
jkijk er morgen naar ga nu tukken
Gewijzigd op 05/03/2006 01:18:00 door - wes -
En volgens mij is het een kwestie van enkele regels toevoegen in het script hierboven om hem geschikt te maken. (correct me if i'm wrong). Alvast bedankt!
Niemand die mij kan helpen?