Hi,
I am working on a image upload and resize form/script. I have the upload working fine. I am now working on screwing it up, errr I mean resizeing. Ultimatly what I want to do is upload one image, and run the script to generate a large, medium, and small/thumbnail versions, and attach to a db. I have started simple, I got the upload to work and attach the location to my db, now what I am trying to do is have the script resize the image once, and save the original. I can admit I am lost, I have botched together diff scripts snippets from here and there, read the manual, and I keep getting dumber and making a bigger mess of the code. If (in between laughing fits at my mess) someone could push me in the right direction I would appreciate it.
<?php
$path = "../images/";
$max_size = 100000000;
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) {
$img = $HTTP_POST_FILES['userfile']['tmp_name'];
// resize function
function thumbnail($i,$nw,$p,$nn) {
$img=imagecreatefromjpeg("$i");
$ow=imagesx($img);
$oh=imagesy($img);
$scale=$nw/$ow;
$nh=ceil($oh*$scale);
$newimg=imagecreate($nw,$nh);
imagecopyresized($newimg,$img,0,0,0,0,$nw,$nh,$ow,$oh);
imagejpeg($newimg, $p.$nn);
return true;
}
#thumbnail(filetouse,newwidth,newpath,newname);
thumbnail("../images/$img",100,"/images/thumbnails/","_thmb.jpg");
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "The file is too big<br>\n"; exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/png")
||($HTTP_POST_FILES['userfile']['type']=="image/pjpeg")
||($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "The file already exists<br>\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path .
$HTTP_POST_FILES['userfile']['name']);
if (!$res) { echo "upload failed!<br>\n"; exit; } else { echo "upload sucessful<br>\n"; }
echo "File Name: ".$HTTP_POST_FILES['userfile']['name']."<br>\n";
echo "File Size: ".$HTTP_POST_FILES['userfile']['size']." bytes<br>\n";
echo "File Type: ".$HTTP_POST_FILES['userfile']['type']."<br>\n";
} else { echo "Wrong file type<br>\n"; exit; }
}
//insert record into table
require ("../connect.php");
$img_full = $HTTP_POST_FILES['userfile']['name'];
$sql = "INSERT INTO port_images (invID,img_full,img_large,img_medium,img_small) VALUES
('7','$img_full','$img_large','$img_medium','$img_small')";
?>