I'm having trouble with adding an item to an online store through I have been updating.
I think it must have to do with the image upload function I am using. If I attach a picture before uploading I get this error:
Permission Denied. Unable to copy file to 'mpmweb/images/store/inventory'
but when I don't attach a file I am still getting an error that states:
No file was uploaded.
Here is my code:
<?
require('../../includes/checklogin.php');
require('../../includes/bldnav.php');
require('../../includes/fileupload-class.php');
function createThumbnail($imageDirectory, $imageName, $thumbDirectory) {
$srcImg = imagecreatefromjpeg("$imageDirectory/$imageName");
$thumbWidth = "100";
$thumbHeight = "100";
$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, imagesx($srcImg), imagesy($srcImg));
$tName = "s" . $imageName;
imagejpeg($thumbImg, "$thumbDirectory/$tName");
}
$host = "localhost";
$user = "********";
$pass = "********";
$db = "********";
$path = "mpmweb/images/store/inventory/";
$upload_file_name = "imgurl";
$acceptable_file_types = "image/gif|image/jpeg|image/pjpeg";
$default_extension = "";
$mode = 2;
$my_uploader = new uploader('en');
$my_uploader->max_filesize(200000);
$my_uploader->max_image_size(410, 410);
if ($my_uploader->upload($upload_file_name, $acceptable_file_types, $default_extension)) {
$my_uploader->save_file($path, $mode);
}
if ($my_uploader->error) {
$errmsg = $my_uploader->error;
}
else {
createThumbnail($my_uploader->file['name'],);
$sql = "insert into tblinventory (subcat,sku,fullcost,salecost,prod,indetail,attributes,simgurl,simgwd,simght,limgurl,limgwd,limght,instock,remnum,flgsell,adduser,addate) VALUES (";
$sql .= "'" . $_POST['sid'] . "', ";
$sql .= "'" . $_POST['sku'] . "', ";
$sql .= "'" . $_POST['fullcost'] . "', ";
$sql .= "'" . $_POST['salecost'] . "', ";
$sql .= "'" . $_POST['prod'] . "', ";
$sql .= "'" . $_POST['indetail'] . "', ";
$sql .= "'" . $_POST['attributes'] . "', ";
$sql .= "'s" . $my_uploader->file['name'] . "', ";
$sql .= "'100', ";
$sql .= "'100', ";
$sql .= "'" . $my_uploader->file['name'] . "', ";
$sql .= "'400', ";
$sql .= "'400', ";
$sql .= "'" . $_POST['instock'] . "', ";
$sql .= "'" . $_POST['remnum'] . "', ";
$sql .= "'" . $_POST['flgsell']. "', ";
$sql .= "'" . $_SESSION['fname'] . " " . $_SESSION['lname'] . "', ";
$sql .= "'" . date("Y-m-d") . "')";
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
mysql_select_db($db) or die ("Unable to select database!");
$result = mysql_query($sql) or die ("Error in query: $sql. " . mysql_error());
mysql_close($connection);
$errmsg = "The store item was successfully saved.";
}
?>
<html><head>
<title>MPM - Administrator</title>
<link rel=stylesheet type="text/css" href="/_mpmadmin/css/admin.css">
<script language="javascript">
<? echo $nav; ?>
</script>
</head>
<body topmargin=10 leftmargin=15>
<table cellspacing=0 cellpadding=0 border=0 width=740>
<tr><td height=50 class=logo colspan=2 align=center>MPM Administrator</td></tr>
<tr class=tbl valign=top>
<td class=nav width=150><script language="javascript" src="/_mpmadmin/includes/mpmmenu.js"></script></td>
<td valign=top>
<table cellpadding=2 cellspacing=2 border=0 width=75%>
<tr><td colspan=2 align=center class=logo>NEW SHOP ITEM</td></tr>
<tr>
<td class=field width=25%>Status</td>
<td class=entry><b><? echo $errmsg; ?></b></td>
</tr>
</table>
</td></tr>
<tr><td colspan=2> </td></tr>
</table>
</body></html>
Any input would be greatly appreciated!
Thanks