Hej everybody,
Thanks for your help so far. I found a tutorial and the upload to the folder now works.
My insert.php file is like this:
define ("MAX_SIZE","10000");
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
$errors=0;
if(isset($_POST['Submit']))
{
$image=$_FILES['image']['name'];
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
echo '<h1>Unknown fileex.!</h1>';
$errors=1;
}
else
{
$size=filesize($_FILES['image']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
echo '<h1>The image is too big!</h1>';
$errors=1;
}
$image_name=time().'.'.$extension;
$newname="images/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Could not upload!</h1>';
$errors=1;
}}}}
if(isset($_POST['Submit']) && !$errors)
{
echo "<h1>Image is uploaded!</h1>";
}
$sql="INSERT INTO products (title, body, price, image)
VALUES
('$_POST[title]','$_POST[body]','$_POST[price]','$_POST[image]')";
if (!mysql_query($sql,$con))
{
die('Fejl: ' . mysql_error());
}
echo "1 product added";
The only thing is miss now is that the filename (f.eks. 1283931724.jpg) could write it to the database.
The "image" filed in the database is empty :-(
Thanks again for all your help so far!