hi everyone
here is a copy of the code i am trying to execute which is intended to upload an image, detect the images file type, generate a thumbnail and place the path to both the image and the thumb in the database. Here is the code and below that the errors output by php. If anyone can shed any light on this i would really aprishiate it, i have tired a few things wiht no success.
<?php
echo "got to checkpoint 1";
include ('c:/web/db_connect.php');
echo "got to checkpoint 1";
$message1 = "";
$message2 = "";
$message3 = "";
echo "got to checkpoint 2";
$idir = $GLOBALS['imagepath'];
$tdir = $GLOBALS['thumbpath'];
$twidth = $GLOBALS['thumbw'];
$theight = $GLOBALS['thumbh'];
echo "got to checkpoint 3";
if(isset($_POST['uploadbtn'])) {
echo "post submit success";
if ($_FILES['image']['error'] == UPLOAD_ERR_OK) {
echo "files image error line ok";
$query = "SELECT itemid FROM stock ORDER BY itemid DESC LIMIT 1";
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_NUM);
$itemid = $row[0];
/*undefined index picture*/ $extension = explode ('.', $_FILES['picture']['name']);
/*undefined offset 1*/ $ext = $extension[1];
echo $ext;
echo "above is the extention";
$uid = mysql_insert_id();
$url = $uid.'.'.$ext; // Set $url To Equal The Filename For Later Use
$size = ($_FILES['image']['size'] / 1024);
if ($_FILES['image']['size'] < 131072) {
if ($_FILES['image']['type'] == "image/jpg" || $_FILES['image']['type'] == "image/jpeg" || $_FILES['image']['type'] == "image/pjpeg") { //Handle JPEG
$copy = copy($_FILES['image']['tmp_name'], "$idir" . "$url"); // Move Image From Temporary Location To Permanent Location
echo $copy;
if ($copy) {
$message1 .= 'Image uploaded successfully.';
$simg = imagecreatefromjpeg("$idir" . $url);
$currwidth = imagesx($simg);
$currheight = imagesy($simg);
if ($currheight > $currwidth) {
$zoom = $twidth / $currheight;
$newheight = $theight;
$newwidth = $currwidth * $zoom;
} else {
$zoom = $twidth / $currwidth;
$newwidth = $twidth;
$newheight = $currheight * $zoom;
}
$dimg = imagecreatetruecolor($newwidth, $newheight);l
imagecopyresampled($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
imagejpeg($dimg, "$tdir" . $url);
imagedestroy($simg);
imagedestroy($dimg);
$message2 .= 'Image resized successfully.<br><br>';
} else {
$message2 .= 'Unable to resize image.<br><br>';
}
} else {
if ($_FILES['picture']['type'] == "image/gif") {
$copy = copy($_FILES['picture']['tmp_name'], "$idir" . "$url");
if ($copy) {
$message1 .= 'Image uploaded successfully.';
$simg = imagecreatefromgif("$idir" . $url);
$currwidth = imagesx($simg);
$currheight = imagesy($simg);
if ($currheight > $currwidth) {
$zoom = $twidth / $currheight;
$newheight = $theight;
$newwidth = $currwidth * $zoom;
} else {
$zoom = $twidth / $currwidth;
$newwidth = $twidth;
$newheight = $currheight * $zoom;
}
$dimg = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
imagegif($dimg, "$tdir" . $url);
imagedestroy($simg);
imagedestroy($dimg);
$message2 .= 'Image resized successfully.<br><br>';
} else {
$message2 .= 'Unable to resize image.<br><br>';
}
} else {
if($_FILES['picture']['type'] == "image/png" || $_FILES['picture']['type'] == "image/x-png") {
$copy = copy($_FILES['picture']['tmp_name'], "$idir" . "$url");
if ($copy) {
$message1 .= 'Image uploaded successfully.';
$simg = imagecreatefrompng("$idir" . $url);
$currwidth = imagesx($simg);
$currheight = imagesy($simg);
if ($currheight > $currwidth) {
$zoom = $twidth / $currheight;
$newheight = $theight;
$newwidth = $currwidth * $zoom;
} else {
$zoom = $twidth / $currwidth;
$newwidth = $twidth;
$newheight = $currheight * $zoom;
}
$dimg = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight);
imagepng($dimg, "$tdir" . $url);
imagedestroy($simg);
/*line 100*/ imagedestroy($dimg);
$message2 .= 'Image resized successfully.<br><br>';
} else {
$message2 .= 'Unable to resize image.<br><br>';
}
} else {
$message1 .= "<font color=\"#8DA900\">Picture Not Uploaded.</font> Incorrect file type <font color=\"#8DA900\">.$ext</font>.
Please upload a .jpeg, .gif , or .png files only."; }
}
}
} else {
$message3 .= "<font color=\"#8DA900\">Picture Not Uploaded.</font> File size <font color=\"#8DA900\">$size KB</font>
is too large. Size Limit: 128KB.<br><br>"; }
$query1 = "INSERT INTO picture (name, size, type, date) VALUES ('{$_FILES['picture']['name']}', '{$_FILES['picture']['size']}', '{$_FILES['picture']['type']}', NOW())";
$result1 = @mysql_query($query1);
$query2 = "INSERT INTO thumbs (name, size, type, date) VALUES ('{$_FILES['picture']['name']}', '{$_FILES['picture']['size']}', '{$_FILES['picture']['type']}', NOW())";
$result2 = @mysql_query($query2);
$query3 = "UPDATE stock SET imagepath = '.$idir./$url' WHERE itemid = '$itemid'";
$result3 = @mysql_query($query3);
$query4 = "SELECT picid FROM picture ORDER BY picid DESC LIMIT 1";
$result4 = @mysql_query($query4);
$row4 = mysql_fetch_array($result4, MYSQL_NUM);
$picid = $row4[0];
$query5 = "UPDATE picture SET url = '.$idir/$url', extension = '$ext' WHERE picid = '$picid'";
/*126*/ $result5 = @mysql_query($query5);
$query6 = "UPDATE stock SET thumbpath = '.$tdir./$url' WHERE itemid = '$itemid'";
$result6 = @mysql_query($query6);
$query7 = "SELECT thumbid FROM thumbs ORDER BY thumbid DESC LIMIT 1";
$result7 = @mysql_query($query7);
$row7 = mysql_fetch_array($result7, MYSQL_NUM);
$thumbid = $row7[0];
$query8 = "UPDATE thumbs SET url = '.$tdir./$url', extension = '$ext' WHERE thumbid = '$thumbid'";
$result8 = @mysql_query($query8);
}
}
if(isset($message)) {
echo "<font class='txt1'>$message</font>";
} else {
echo "<p>Please select a picture to upload this line is at end of file</p>";
/*error 142*/ }
if(isset($message2)) {
echo "<font class='txt1'>$message1 | $message2</font>";
} else {
echo "<font class='txt1'>$message3</font>";
}
?>
ERRORS OUTPUT
this is exactly what is output by the browser:
got to checkpoint 1got to checkpoint 1got to checkpoint 2got to checkpoint 3post submit successfiles image error line ok
Notice: Undefined index: picture in C:\web\root\devfiles\upload.php on line 28
Notice: Undefined offset: 1 in C:\web\root\devfiles\upload.php on line 29
above is the extention
Notice: Undefined index: picture in C:\web\root\devfiles\upload.php on line 126
Notice: Undefined index: picture in C:\web\root\devfiles\upload.php on line 126
Notice: Undefined index: picture in C:\web\root\devfiles\upload.php on line 126
Notice: Undefined index: picture in C:\web\root\devfiles\upload.php on line 128
Notice: Undefined index: picture in C:\web\root\devfiles\upload.php on line 128
Notice: Undefined index: picture in C:\web\root\devfiles\upload.php on line 128
Please select a picture to upload this line is at end of file
|