i got a little problem with my script. I would like to upload image into a PostgreSQL database. But it gives me an error (see below). Has someone found an easy way to solve this problem?
The code:
<?php
$uploaddir = '/home/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$name = $_POST['name'];
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{ echo "File is valid, and was successfully uploaded.
";
}
else { echo "File size greater than 300kb!
"; }
echo "'$name'
";
$host = "localhost";
$user = "postgres";
$pass = "qwe123";
$db = "baza";
$con = pg_connect("host=$host dbname=$db user=$user password=$pass")
or die ("Could not connect to server
");
$query = "insert into image values ('$name', lo_import('$uploadfile'), 'now')";
$result = pg_query($query);
if($result)
{
echo "File is valid, and was successfully uploaded.
";
unlink($uploadfile);
}
else
{
echo "Filename already exists. Use another filename. Enter all the values.";
unlink($uploadfile);
}
pg_close($con);
?>
fails with:
Warning: move_uploaded_file(/home/gora.jpg): failed to open stream: No such file or directory
in C:\xampp\htdocs\postgretest\image.php on line 24
Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php3A3.tmp' to '/home/gora.jpg'
in C:\xampp\htdocs\postgretest\image.php on line 24
File size greater than 300kb! 'dfd'
Warning: pg_query(): Query failed: Error: Can not open the file server "/home/gora.jpg": No such file or directory
in C:\xampp\htdocs\postgretest\image.php on line 38
Filename already exists. Use another filename. Enter all the values.
Warning: unlink(/home/gora.jpg): No such file or directory
in C:\xampp\htdocs\postgretest\image.php on line 48