douwei1950 2014-02-23 06:46 采纳率: 0%
浏览 6
已采纳

不在数据库中发布

I am not getting any error. But image which I am uploading is not saving in images/photo/ directory.
I see in my database is there any problem in it? Please help me..thank you. and sorry for disturbing i'm just new in PHP language.

Here's my code in saving:

<?php

include('connect.php');

if (isset($_POST['save'])) {
    addpost($_POST['fname'], $_POST['cont'], $_POST['mail'], $_POST['add'], $_POST['description'], $_FILES["image"] ["name"], $_FILES["image"] ["type"], $_FILES["image"] ["size"], $_FILES["image"] ["tmp_name"], $_FILES["image"] ["error"]);
    echo $success = "<script language='javascript' >
    alert('Your Post has been successfuly added!')
    window.location='post.php'
    </script>";
}
?>

And here's my code in connect.php :

function addpost($a, $b, $c, $d, $e, $name, $type, $size, $tmp_name, $error) {
    $img = 'images/posts/' . $name;
    mysql_query("INSERT post(p_name,p_contact,p_email,p_address,description,photo,dateadded) values 
('$a','$b','$c','$d','$e','$img',NOW())");

    if ($error > 0) {
        die("Error uploading file! Code $error.");
    } else {
        if ($size > 10000000000) {
            die("Format is not allowed or file size is too big!");
        } else {
            move_uploaded_file($tmp_name, "images/posts/" . $name);
        }
    }
}
  • 写回答

1条回答 默认 最新

  • dpyln64620 2014-02-23 06:56
    关注

    Yes for file upload you need to add enctype='multipart/form-data' in the form so your form should be as

    <form action="" method="post" enctype="multipart/form-data" onSubmit="return ValidateForm(this);">
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么