dos8244 2014-05-22 12:52
浏览 56

Postgresql php插入图片

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
  • 写回答

1条回答 默认 最新

  • donxbje866688 2014-05-23 10:30
    关注

    The errors you show have nothing whatsoever to do with PostgreSQL. The move_uploaded_file function is failing with the errors given above. The error suggests that the file is probably too large for your PHP configuration to process given its available memory - note in particular:

     File size greater than 300kb! 'dfd' 
    

    Make sure you can upload the file correctly. Then work on inserting it into the database. While you're at it, put some error handling in your code.

    You should enable exceptions, or check function return error codes and exit the script on an error. Don't just continue blindly. Once you've hit one error, the rest of the code isn't going to work, after all.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。