Uploadscriptje 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 (temporarily not .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"))
{
echo("You can only upload .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 (temporarily not .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"))
{
echo("You can only upload .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);
}
}
?>
Heb ik er niet helemaal duidelijk bij gezet. Alvast bedankt!
http://www.phphulp.nl/php/scripts/ op deze site. ik gebruik zelf http://www.phphulp.nl/php/scripts/2/129/
echter lees wel de comments
zoek eens op echter lees wel de comments
http://www.phphulp.nl/php/scripts/9/464/
Eentje om aan te roepen en nog een andere, waar moet ik die plaatsen? En kun je via dat script ook als uploader de naam opgeven hoe het bestand weggeschreven wordt?
Hoe werkt dat dan met die twee php files? --> Eentje om aan te roepen en nog een andere, waar moet ik die plaatsen? En kun je via dat script ook als uploader de naam opgeven hoe het bestand weggeschreven wordt?
moet je includen in je bestand de andere is gewoon een voorbeeld hoe je het moet aan roepen.
en ik zou er ff een header bij pleuren op z'n minst header("content-type: image");, maar ik weet niet of dat mag zonder dat je defineerd welk specefiek type het is
Of heb ik dat nu verkeerd?
en niet dezelfde vraag 2x topic voor maken, niet netjes
Dat laatst gaat niet lukken omdat er nog meer specifieke functies voor het aanpassen van het bestand zijn...
//Check if the file-type is JPG or GIF
elseif(($_FILES['bestand']['type'] != "image/jpeg") && ($_FILES['bestand']['type'] != "image/pjpeg") &&
($_FILES['bestand']['type'] != "image/gif"))
{
echo("You can only upload .jpg or .gif" );
echo($_FILES['bestand']['type']);
}
else
{
Maar dan heb je nog niet genoeg veranderd, er moet nog iets worden veranderd in het wegschrijf gedeelte, maar daar kwam ik dus niet uit.
@ wes, sorry maar niemand reageerde op dat andere topic
De foutmeldingen erbij:
Warning: imagecreatefromjpeg(): gd-jpeg: JPEG library reports unrecoverable error: in /home/worldpixel/domains/worldpixelcenter.com/public_html/picturesphp2.php on line 47
Warning: imagecreatefromjpeg(): '/var/tmp/phpHRN5Xm' is not a valid JPEG file in /home/worldpixel/domains/worldpixelcenter.com/public_html/picturesphp2.php on line 47
Warning: imagesx(): supplied argument is not a valid Image resource in /home/worldpixel/domains/worldpixelcenter.com/public_html/picturesphp2.php on line 49
Warning: imagesy(): supplied argument is not a valid Image resource in /home/worldpixel/domains/worldpixelcenter.com/public_html/picturesphp2.php on line 50
Warning: imagecreatetruecolor(): Invalid image dimensions in /home/worldpixel/domains/worldpixelcenter.com/public_html/picturesphp2.php on line 80
Can't process picture
Het script is als volgt:
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
103
104
105
106
107
108
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
103
104
105
106
107
108
<?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=\"picturesphp2.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 or GIF
elseif(($_FILES['bestand']['type'] != "image/jpeg") && ($_FILES['bestand']['type'] != "image/pjpeg") &&
($_FILES['bestand']['type'] != "image/gif"))
{
echo("You can only upload .jpg or .gif" );
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();
if($_FILES['bestand']['type'] == "image/gif") {
Imagegif($destination);
} else {
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=\"picturesphp2.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 or GIF
elseif(($_FILES['bestand']['type'] != "image/jpeg") && ($_FILES['bestand']['type'] != "image/pjpeg") &&
($_FILES['bestand']['type'] != "image/gif"))
{
echo("You can only upload .jpg or .gif" );
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();
if($_FILES['bestand']['type'] == "image/gif") {
Imagegif($destination);
} else {
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);
}
}
?>
Ik ben er uit! Allemaal hartstikke bedankt voor de hulp!