Hello, I'm back.
This is one that I can't seem to see the error with. I have a script that takes a pic and creates a thumbnail out of it. This script uses a function. When I run the script by itself, it works great.
However, when I run it with other code php spits out a Fatal Error: Function undefined. What does it mean by undefined? Here is the code that crashes. The thumbnail part is about halfway down.
Thank you in advance.
lokokolo
<?php
// Test to see if a submission was made
if (isset($_POST["mfr"])) {
// connect to mysql and select database
$conn = mysql_connect("localhost", "root");
$db = mysql_select_db("bri", $conn);
if (!$conn) { echo("ERROR: " . mysql_error() . "\n"); }
// Insert data into db
$mfr = $POST["mfr"];
$prod = $POST["prod"];
$descrip = $POST["descrip"];
$mfrmonth = $POST["mfrmonth"];
$mfryear = $POST["mfryear"];
$invdate = date("F j, Y, g:i a");
$paint = $POST["paint"];
$laminate = $POST["laminate"];
$panel = $POST["panel"];
$qty = $POST["qty"];
$monthavail = $POST["monthavail"];
$dayavail = $POST["dayavail"];
$yearavail = $POST["yearavail"];
$laminate = $POST["laminate"];
$condition = $POST["condition"];
$picdescrip = $_POST["picdescrip"];
$insert = ("INSERT INTO inventory (invdate, mfr, prod, descrip, mfrmonth, mfryear, paint, laminate, panel, qty, monthavail,
dayavail, yearavail, condition, picdescrip) VALUES ('$invdate', '$mfr', '$prod', '$descrip', '$mfrmonth', '$mfryear',
'$paint', '$laminate', '$panel', '$qty', '$monthavail', '$dayavail', '$yearavail', '$condition', '$picdescrip')");
$sql = mysql_query($insert, $conn);
if (!$sql) { echo("ERROR: " . mysql_error() . "\n"); }
//* Create Folder and Store Picture ***//
// get invid
$getinfo = mysql_query("SELECT invid FROM inventory
WHERE '$invdate' = inventory.invdate");
while ($row = mysql_fetch_object($getinfo)) {
$picid = $row->invid;
}
// Create Folders
mkdir ("invpics/" . $picid . "/", 0755);
chmod ("invpics/" . $picid . "/", 0777);
mkdir ("invpics/" . $picid . "/thumb/", 0755);
chmod ("invpics/" . $picid . "/thumb/", 0777);
// echo ($picid . " folder was created <br>");
// if (is_uploaded_file($_FILES['invpic']['tmp_name'])) {
// echo "yes it uploaded!<br>";
// }
// echo ("Error #: " . $_FILES['invpic']['error']);
// Move uploaded pic
if (is_uploaded_file($FILES['invpic']['tmp_name'])) {
move_uploaded_file($FILES['invpic']['tmp_name'], "invpics/" . $picid . "/" . $invpic_name);
echo ("<font color=\"#FF0000\">Your submission was successful! <br><br> Where can we take you?</font>");
} else {
echo "Possible file upload attack. Filename: " . $FILES['invpic']['name'] . "<br>";
}
// copy($FILES['invpic']['tmp_name'], "invpics/" . $picid . "/");
/ ...or... /
// move_uploaded_file($_FILES['invpic']['tmp_name'], "invpics/" . $picid . "/" . $invpic_name);
// ********************************* Create The Thumbnail ************************************* //
$image_path = ("invpics/" . $picid . "/");
$thumb_path = ($image_path . "thumb/");
//echo "<br>";
//echo $image_path;
// echo "<br>";
$files = opendir($image_path) or die("Cannot opendir the folder");
// echo $files;
$file = readdir($files);
//echo "<br>";
//echo $file;
thumbnail($image_path,$thumb_path,$file,150);
function thumbnail ($image_path,$thumb_path,$image_name,$boundry) {
$src_img = imagecreatefromjpeg("$image_path/$image_name");
$origw = imagesx($src_img);
$origh = imagesy($src_img);
if ( $origw >= $origh )
{ // begin if #1
$factor = $boundry/$origw;
$t_imagew = $boundry;
$t_imageh = $origh * $factor;
} // end if #1
if ( $origh > $origw )
{ // begin if #2
$factor = $boundry/$origh;
$t_imageh = $boundry;
$t_imagew = $origw * $factor;
} // end if #2
$dst_img = imagecreate($t_imagew,$t_imageh);
imagecopyresized($dst_img,$src_img,0,0,0,0,$t_imagew,$t_imageh,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, "$thumb_path/$image_name");
return true;
} // end thumbnail function
} // end ISSET