Witam! Wiem ze było wiele takich tematów na tym forum i w innych przypadkach mi pomogły ale w tym nie mogę sobie poradzić, a więc mam 2 skrypty:
<?php
if(isset($_POST['submit'])) {
$target = "../uploads/";
$allowedExts = array("jpg", "jpeg"); $extension = end(explode(".", $_FILES["file_upload"]["name"])); $target = $target . basename( $_FILES['file_upload']['name']); $date = date("Y-m-d H:i:s");
//Function to generate image thumbnails
function make_thumb($src, $dest, $desired_width) {
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height * ($desired_width / $width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width, $desired_height);
/* copy source image at a resized size */
imagecopyresampled($virtual_image, $source_image, 0, 0, 0, 0, $desired_width, $desired_height, $width, $height);
/* create the physical thumbnail image to its destination with 100% quality*/
imagejpeg($virtual_image, $dest,100);
}
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or
die ("Error connecting to database");
//check for allowed extensions
if ((($_FILES["file_upload"]["type"] == "image/jpg")|| ($_FILES["file_upload"]["type"] == "image/jpeg"))&& in_array($extension, $allowedExts)) {
$photoname = $_FILES["file_upload"]["name"];
{
die( '<div class="error">Sorry <b>'. $photoname . '</b> already exists</div>'); }
{
$query = "INSERT INTO photos (photo_name,date_added) VALUES ('$photoname','$date')";
$sql = "SELECT MAX(id) FROM photos";
$maxId = $row['MAX(id)'];
$type = $_FILES["file_upload"]["type"];
switch($type)
{
case "image/jpeg":
$ext = ".jpeg";
break;
case "image/jpg";
$ext = ".jpg";
break;
}
//define arguments for the make_thumb function
$source = "../uploads/".$photoname;
$destination = "../thumbnails/thumb_". $maxId . $ext ."";
//specify your desired width for your thumbnails
$width = "482";
//Finally call the make_thumb function
make_thumb($source,$destination,$width);
$msg = '<div class="success">
<b>Upload: </b>' . basename($photoname) . '<br /> <b>Type: </b>' . $_FILES["file_upload"]["type"] . '<br />
<b>Size: </b>' . ceil(($_FILES["file_upload"]["size"] / 1024)) . 'Kb<br /> </div>';
}
else
{
$msg = '<div class="error">Sorry, there was a problem uploading your file.</div>';
}
}
else
{
$msg = '<div class="error">The file type you are trying to upload is not allowed!</div>';
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Upload Image</title>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<H3>Upload Images Here</H3>(<a href="../" target="_blank">View Gallery</a>)
<div id="upload">
<form action="" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="text" name="name"/><BR/>
<input type="file" name="file_upload" id="upload_file" />
<input type="submit" name="submit" value="Upload" />
</form>
</div>
</body>
</html>
Pytanie moje brzmi w którym miejscu wstawić skrypt z biblioteki do skryptu nr 2 tak aby zmniejszało obrazki przy uploadzie? No i oczywiście zamiast konkretnej nazwy pliku trzeba wstawić zmienną.
Proszę o pomoc, pozdrawiam.
Ten post edytował aldzik 20.02.2013, 16:19:56