acid007
Gebruiker
- Lid geworden
- 13 jun 2002
- Berichten
- 775
Ik heb inmiddels een uploadscript dat prima werkt, hij schrijft het ook in de database (mySQL) en werkt prachtig om iets erop te zetten.
Nadeel; ik weet niet hoe ik iets weer kan VERWIJDEREN. Kan iemand mij helpen?
Hier het uploadscript:
Nadeel; ik weet niet hoe ik iets weer kan VERWIJDEREN. Kan iemand mij helpen?
Hier het uploadscript:
PHP:
?
$path = "screenshots/"; // folder waarin de plaatjes moet komen
$max_witdh = 1024; // de maximale hoogte van het plaatje
$max_height = 768; // de maximale breedte van het plaatje
$name = "scrshot"; // naam van het plaatje (eerst bestand wordt pict0.jpg, pict1.jpg, etc...)
$kwaliteit = "90"; // kwaliteit waarmee de JPG bewaard wordt
function ImageCopyResampleBicubic (&$dst_img, &$src_img, $dst_x,
$dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
/*
port to PHP by John Jensen July 10 2001 (updated 4/21/02) -- original code
(in C, for the PHP GD Module) by [email]jernberg@fairytale.se[/email]
*/
{
$palsize = ImageColorsTotal ($src_img);
for ($i = 0; $i < $palsize; $i++) { // get palette.
$colors = ImageColorsForIndex ($src_img, $i);
ImageColorAllocate ($dst_img, $colors['red'], $colors['green'],
$colors['blue']);
}
$scaleX = ($src_w - 1) / $dst_w;
$scaleY = ($src_h - 1) / $dst_h;
$scaleX2 = (int) ($scaleX / 2);
$scaleY2 = (int) ($scaleY / 2);
for ($j = $src_y; $j < $dst_h; $j++) {
$sY = (int) ($j * $scaleY);
$y13 = $sY + $scaleY2;
for ($i = $src_x; $i < $dst_w; $i++) {
$sX = (int) ($i * $scaleX);
$x34 = $sX + $scaleX2;
$color1 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $sX,
$y13));
$color2 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $sX,
$sY));
$color3 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $x34,
$y13));
$color4 = ImageColorsForIndex ($src_img, ImageColorAt ($src_img, $x34,
$sY));
$red = ($color1['red'] + $color2['red'] + $color3['red'] +
$color4['red']) / 4;
$green = ($color1['green'] + $color2['green'] + $color3['green'] +
$color4['green']) / 4;
$blue = ($color1['blue'] + $color2['blue'] + $color3['blue'] +
$color4['blue']) / 4;
ImageSetPixel ($dst_img, $i + $dst_x - $src_x, $j + $dst_y - $src_y,
ImageColorClosest ($dst_img, $red, $green, $blue));
}
}
}
$file = $_FILES["image"]["name"]; // pakt bestandsnaam van de geselecteerde plaatje
$image = $_FILES["image"]["tmp_name"];
$type = $_FILES["image"]["type"]; // bestands type pakken
if ($type == "image/pjpeg" XOR $type == "image/jpeg") {
$src_img = ImageCreateFromJPEG($image);
$img_w = imagesx($src_img);
$img_h = imagesy($src_img);
if ($img_w > $img_h) {
if ($img_w > $max_witdh) {
$dst_w = $max_witdh;
$factor = $img_w / $dst_w;
$dst_h = $img_h / $factor;
} else {
$dst_w = $img_w;
$dst_h = $img_h;
}
} else {
if ($img_h > $max_height) {
$dst_h = $max_height;
$factor = $img_h / $dst_h;
$dst_w = $img_w / $factor;
} else {
$dst_w = $img_w;
$dst_h = $img_h;
}
}
ob_start();
phpinfo(8);
$phpinfo=ob_get_contents();
ob_end_clean();
$phpinfo=strip_tags($phpinfo);
$phpinfo=stristr($phpinfo,"gd version");
$phpinfo=stristr($phpinfo,"version");
$end=strpos($phpinfo," ");
$phpinfo=substr($phpinfo,0,$end);
$phpinfo=substr($phpinfo,7);
if(version_compare("2.0", "$phpinfo")==1) {
$dst_img = imagecreate($dst_w,$dst_h);
} else {
$dst_img = imagecreatetruecolor($dst_w,$dst_h);
}
if($img_w > $max_witdh || $img_h > $max_height) {
ImageCopyResampleBicubic($dst_img,$src_img,0,0,0,0,$dst_w,$dst_h,$img_w,$img_h);
} else {
imagecopy($dst_img,$src_img,0,0,0,0,$img_w,$img_h);
}
if (!file_exists($path)) {
mkdir($path, 0775);
}
$i = 0;
while (file_exists($path.$name.$i.".jpg")) {
$i = $i + 1;
}
$name = $name . $i;
imagejpeg($dst_img, $path.$name.".jpg", $kwaliteit);
imagedestroy($dst_img);
imagedestroy($src_img);
$end_map = "http://www.cmunited.nl/$path";
$end_name = "$name.jpg";
$url = "$end_map$end_name";
// het in de database schrijven
$sql = " INSERT INTO screenshots";
$sql .= " (naam, info, url) VALUES ";
$sql .= " ('$naam', '$info', '$url') ";
$result = mysql_query($sql);
if (mysql_error()) { print "Database ERROR: $sql " . mysql_error();
}
echo "<b>Naam:</b> $naam<br>";
echo "<b>Info:</b> $info<br>";
echo "<img src=\"".$path.$name.".jpg\" border=\"0\"><p>";
echo "Het plaatje is geupload naar de server.<br>";
echo "Hier staat hij: <a href=\"$end_map$end_name\">$end_map$end_name</a>";
} else {
echo "Alleen JPG files toegstaan, GIF files zijn tegroot";
}
?>