A question about uploading an image to my database.
(same question as in other topic, but I need to finish it within 12 hours..)
I used the tutorial recommended above, but it seems as if I'm to plain dumb to get it to work, I followed the instructions, but it's not working, I get errors about these lines:
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
Warning: fread(): supplied argument is not a valid stream resource in /home/vhosting/21/sintpietersgent.be/www/leerlingenraad/seminarie/insert.php on line 26
Warning: fclose(): supplied argument is not a valid stream resource in /home/vhosting/21/sintpietersgent.be/www/leerlingenraad/seminarie/insert.php on line 28
This is the entire code:
bestellingenCP.php
<table>
<form enctype="multipart/form-data" action="insert.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<tr><td>Afbeelding:</td><td><input name="image" accept="image/jpeg" type="file"></td></tr>
<tr><td>Naam:</td><td><input name="naam" type="text" /></td></tr>
<tr><td>Prijs:</td><td><input name="prijs" type="text" /></td></tr>
<tr><td>Omschrijving:</td><td><textarea name="omschrijving" ></textarea></td></tr>
<tr><td></td><td><input value="Submit" type="submit"></td></tr>
</form>
</table>
insert.php (the problem..)
<?php
$host="localhost";
$name = "correct";
$pass = "correct";
$dbname = "correct";
$dbi = mysql_connect($host, $name,$pass) or
die("Kan niet verbinden met de database. Error :" . mysql_error());
mysql_select_db($dbname,$dbi);
if (isset($_FILES['image'])) {
$tmpName = $_FILES['image']['tmp_name'];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
$naam = $_POST['naam'];
$prijs = $_POST['prijs'];
$omschrijving = $_POST['omschrijving'];
$query = "INSERT INTO bestellingen (naam,prijs,beschrijving,image) VALUES
('$naam','$prijs','$omschrijving','$data')";
$results = mysql_query($query, $dbi);
}
else {
print "No image selected/uploaded";
}
mysql_close($dbi);
?>