PHP Code:
$uploadedfile = $_FILES['userfile']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
list($width, $height) = getimagesize($uploadedfile);
$newwidth = 100;
$newheight = ($height / $width) * 100;
$tmp = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
$img = "images/" . $_FILES['userfile']['name'];
$t = 1;
while(file_exists($img)){
$img = "images/" . $_FILES['userfile']['name'];
$img = substr($img, 0, strpos($img, ".")) . "-$t" . strstr($img, ".");
$t++;
}
imagejpeg($tmp, $img, 100);
//insert into table set image_path='$img'...
Bookmarks