Hi you all,
I'm fairly new to php. For my job, I have to create a website. I have designed a system where all employers can add products from our company to the website. That al worked (works) like a charm. But then I've got ambitious 🙂. I want to give the users a possibility to upload pictures from the product too. If searched and found a script on the net, which works fine in his standard way. But when I try to implement it in my existing code, it does not work. It returns the (programmed) error messager "Het uploaden van is niet gelukt". But I don't know where my error is... It would be extremely kind of y'all if it's possible to check it out...
Here is my code
webedit.php:
<?php
session_start();
if ($Login == '1') {
?>
<? include ("navigation.inc")?>
<p align="left"><font color="#333333" size="2" face="Verdana, Arial, Helvetica, sans-serif">[<a href="webedit.php?action=addproduct">Add a product to the website</a> ] </font></p>
<?
if ($HTTP_POST_VARS['Submit'])
{
include ("pictureupload.php");
$db = mysql_connect("localhost", "user", "pass") or die ("Connection was not possible");
mysql_select_db("integra", $db);
$sql1 = "INSERT INTO integraweb_products(productname, productinfo, productcat, picturepath) VALUES ('$productnaam','$productinfo', '$productcategorie', 'http://www.integra-belgium.com/full/'".$file."') ";
$resultset = mysql_query($sql1);
echo "<font color=\"#666666\" size=\"2\" face=\"Tahoma, Arial\"><strong>Product has been successfully added to the website.</strong></font>";
}
?>
<?
if ($_GET['action'] == "addproduct"){
include ("addproduct.php");
}
?>
</div>
</td>
</tr>
<?php
}
else {
echo "<script type='text/javascript' language='JavaScript'>document.location.href='/intranet/index.php';</script>";
}
?>
pictureupload.php:
<?
$thumbdir = "thumb/";
$fulldir = "full/";
$file = basename($_FILES['image']['name']);
$ext = explode(".", $file);
$ext_num = count($ext);
$path = "$thumbdir";
$file_extension = $ext[$ext_num-1];
$n=$naam;
while (file_exists($path.$n.".".strtoupper($file_extension))) {
$n = $n + 1;
}
# filename that is saved as image (no extension)
$filename = "$thumbdir$n";
# resize values
$resizewidth = 200;
$resizeheight = 200;
# resize
include("function.php");
if(isset($_FILES['image']['size'])) {
if($_FILES['image']['type'] == "image/pjpeg") {
$im = imagecreatefromjpeg($_FILES['image']['tmp_name']);
}
elseif($_FILES['image']['type'] == "image/x-png") {
$im = imagecreatefrompng($_FILES['image']['tmp_name']);
}elseif($_FILES['image']['type'] == "image/gif") {
$im = imagecreatefromgif($_FILES['image']['tmp_name']);
}
if(isset($im)){
if(file_exists("$filename.jpg")) {
unlink("$filename.jpg");
}
ResizeImage($im,$resizewidth,$resizeheight,$filename);
ImageDestroy ($im);
}
}
# saving the original
$path = "$fulldir";
$file_size = round($_FILES['image']['size'] / 1024);
$file_type = $_FILES['image']['type'];
$file = basename($_FILES['image']['name']);
$ext = explode(".", $file);
$ext_num = count($ext);
$file_extension = $ext[$ext_num-1];
$n=$naam;
while (file_exists($path.$n.".".strtoupper($file_extension))) {
$n = $n + 1;
}
if(move_uploaded_file($_FILES['image']['tmp_name'], $path.$n.".".strtoupper($file_extension))) {
echo"The picture<b>".$file."</b> with a filesize of <b>".$file_size."</b> kb, with extension<b>.".$file_extension."</b> is succesfully uploaded to<b>".$path."</b> as <b>".$n.".".$file_extension."</b>";
}
else {
echo"File: <b>".$file."</b> could not be uploaded. There was an error.";
}
?>
addproduct.php:
<?php
echo '<form name="form1" id="form1" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="25%" align="left" scope="row"><span class="style7">Productname</span></th>
<td width="75%"><input type="text" name="productnaam" /></td><br>
</tr>
<tr align="left">
<th scope="row"><span class="style7">Productinformation</span></th>
<td><textarea name="productinfo" cols="50" rows="10" wrap="OFF"></textarea> </td>
</tr>
<tr align="left">
<th scope="row"><span class="style7">Categorie</th>
<td><select name="Category">
<option>Make your choice!</option>
<option>HDL</option>
<option>braillenotitietoestellen</option>
<option>brailledrukkers</option>
<option>Low Vision</option>
<option>brailledisplays</option>
<option>software</option>
</select>
<br></td>
</tr>
<tr align="left">
<th scope="row"><br></th>
<tr>
<th width="25%" align="left" scope="row"><span class="style7">Image</span></th>
<td width="75%"><input type="file" name="image" /></td><br>
</tr>
<tr>
<th width="25%" align="left" scope="row"><span class="style7">Imagename</span></th>
<td width="75%"><input type="text" name="naam" /></td><br>
</tr>
<tr>
<th width="25%" align="left" scope="row"></th>
<td width="75%"></td><br>
</tr>
<tr>
<td><input type="submit" name="Submit" value="Submit"></td>
</tr>
</table>
</form>';
?>
Thanks in advance...