gif en png ook in dit script?
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
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
<?php
$upload_directory = "pictures"; // hier word de foto eerst geupload!
$save_dir = "files"; // hier word de foto opgeslagen!
$max_uploads = "2"; // max uploads
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ($_POST['files'])
{ if (empty($username)) {echo "<script>alert('Je hebt je username niet ingevuld.'); document.location.href=('index2.html')</script>";}
printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload');
for ($i = 1; $i <= $_POST['files']; $i++)
{
printf('       <input type="file" name="file_%s" size="50"><br />', $i);
}
printf('       <input type="button" onclick="javascript: history.back(-1);" value="Terug">');
printf('<input type="submit" value="Upload bestand(en)">');
printf("<input type=\"hidden\" name=\"username2\" value='$username'>");
printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']);
printf('</form>');
}
else
{
printf('<h3>       Resultaten:</h3>');
printf('<table border="1">');
for ($i = 1; $i <= $_POST['history_files']; $i++)
{
$username = $_POST['username'];
$tmp_filename = $_FILES['file_'.$i]['tmp_name'];
$filename = $_POST['username2']."-".$_FILES['file_'.$i]['name'];
if (move_uploaded_file($tmp_filename, $upload_directory.'/'.$filename))
{
$status = '<a href="\files/foto_album.php"\>Verzonden...Bekijk de foto\'s</a>';
$up_file = $upload_directory.'/'.$filename;
$srcimage = imagecreatefromjpeg($up_file);
$width = imageSX($srcimage);
$height = imageSY($srcimage);
if($width <= 640 && $height <= 480){
$t_width=$width;
} else {
if ($height < $width){
$t_width = 640;
}
else {
$t_width = 480;
}
}
$newh1= $height / $width;
$newh2= $newh1 * $t_width;
$destimage = imagecreatetruecolor($t_width,$newh2);
imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height);
ob_start();
ImageJPEG($destimage,'',100);
$buffer = ob_get_contents();
ob_end_clean();
$file=$save_dir.'/'.$filename;
$handle = fopen($file, 'ab');
fwrite($handle, $buffer);
fclose($handle);
$delete=$upload_directory.'/'.$filename;
@unlink($delete);?>
$upload_directory = "pictures"; // hier word de foto eerst geupload!
$save_dir = "files"; // hier word de foto opgeslagen!
$max_uploads = "2"; // max uploads
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if ($_POST['files'])
{ if (empty($username)) {echo "<script>alert('Je hebt je username niet ingevuld.'); document.location.href=('index2.html')</script>";}
printf('<form method="post" action="%s" enctype="multipart/form-data">', '?page=admin&link=upload');
for ($i = 1; $i <= $_POST['files']; $i++)
{
printf('       <input type="file" name="file_%s" size="50"><br />', $i);
}
printf('       <input type="button" onclick="javascript: history.back(-1);" value="Terug">');
printf('<input type="submit" value="Upload bestand(en)">');
printf("<input type=\"hidden\" name=\"username2\" value='$username'>");
printf('<input type="hidden" name="history_files" value="%s">', $_POST['files']);
printf('</form>');
}
else
{
printf('<h3>       Resultaten:</h3>');
printf('<table border="1">');
for ($i = 1; $i <= $_POST['history_files']; $i++)
{
$username = $_POST['username'];
$tmp_filename = $_FILES['file_'.$i]['tmp_name'];
$filename = $_POST['username2']."-".$_FILES['file_'.$i]['name'];
if (move_uploaded_file($tmp_filename, $upload_directory.'/'.$filename))
{
$status = '<a href="\files/foto_album.php"\>Verzonden...Bekijk de foto\'s</a>';
$up_file = $upload_directory.'/'.$filename;
$srcimage = imagecreatefromjpeg($up_file);
$width = imageSX($srcimage);
$height = imageSY($srcimage);
if($width <= 640 && $height <= 480){
$t_width=$width;
} else {
if ($height < $width){
$t_width = 640;
}
else {
$t_width = 480;
}
}
$newh1= $height / $width;
$newh2= $newh1 * $t_width;
$destimage = imagecreatetruecolor($t_width,$newh2);
imagecopyresampled($destimage,$srcimage,0,0,0,0,$t_width,$newh2,$width,$height);
ob_start();
ImageJPEG($destimage,'',100);
$buffer = ob_get_contents();
ob_end_clean();
$file=$save_dir.'/'.$filename;
$handle = fopen($file, 'ab');
fwrite($handle, $buffer);
fclose($handle);
$delete=$upload_directory.'/'.$filename;
@unlink($delete);?>
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
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
<?
}
else
{
$status = 'Fout!';
}
printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)?$filename:' ', $status);
}
printf('</table>');
}
}
else
{
printf('<form method="post" action="%s">', '?page=admin&link=upload');
printf('       <font color=\"red\" size=\"10\"><b>Hier uploaden</b><br><br></font>');
printf('       Username:<input type="text" name="username">');
printf('       Aantal upload\'s: ');
printf('<select name="files">');
for ($i = 1; $i <= $max_uploads; $i++)
{
printf('<option value="%1$s">%1$s', $i);
}
printf('</select> ');
printf('<input type="submit" value="Verder">');
printf('</form>');
}
?>
}
else
{
$status = 'Fout!';
}
printf('<tr><td>%s</td><td>%s</td><td>%s</td></tr>', $i, ($filename)?$filename:' ', $status);
}
printf('</table>');
}
}
else
{
printf('<form method="post" action="%s">', '?page=admin&link=upload');
printf('       <font color=\"red\" size=\"10\"><b>Hier uploaden</b><br><br></font>');
printf('       Username:<input type="text" name="username">');
printf('       Aantal upload\'s: ');
printf('<select name="files">');
for ($i = 1; $i <= $max_uploads; $i++)
{
printf('<option value="%1$s">%1$s', $i);
}
printf('</select> ');
printf('<input type="submit" value="Verder">');
printf('</form>');
}
?>
Ik dacht dat ik eerst moest controleren op het type(hoe doe ik dat?) en dan...?
Gewijzigd op 05/01/2006 19:49:00 door Dennis van der Meer
# imagecreatefromgd2part
# imagecreatefromgd
# imagecreatefromgif
# imagecreatefromjpeg
# imagecreatefrompng
# imagecreatefromstring
# imagecreatefromwbmp
# imagecreatefromxbm
# imagecreatefromxpm
http://nl2.php.net/manual/nl/function.imagecreate.php
Oke thnx, ik gaat het ff uitvogelen.
Heeft iemand een link naar een script die 2 foto's per keer kan uploaden, resized en dan jpg, png en gif kan resizen?
Laat maar. ik heb al iets gevonden.
grote kans dat gif niet gaat lukken omdat het vanwege copyrights niet meer in gd zit vanaf 1.6