doudou1309 2014-01-29 18:17
浏览 19

将照片上传到文件夹,将照片名称上传到数据库

if ($_SERVER["REQUEST_METHOD"] == "POST")
    {

    $product_naam = clean_input($_POST["product_naam"]);
    $product_specificaties = clean_input($_POST["product_specificaties"]);
    $product_categorie = clean_input($_POST["product_categorie"]);
    $product_soort = clean_input($_POST["product_soort"]);
    $prijs = clean_input($_POST["prijs"]);


    //als form gesubmit is
    if (isset($_POST['submit']))
        {
        //devinieert de image file variabele
        $foto = $_FILES["file"]["name"];
        //maakt tijdelijke naam voor in tmp map
        $tmp_name = $_FILES['file']['tmp_name'];
        $error = $_FILES['file']['error'];

        //moved de image file naar uploads map als er gesubmit is
        if (isset ($foto)) 
            {
            if (!empty($foto)) 
                {
                $location = 'uploads/';
                move_uploaded_file($tmp_name, $location.$foto);
                }
            } 
        }
    //sql insert voor product toevoegen
    $sql = "INSERT INTO producten ( prijs, product_naam, product_specificaties, foto, product_categorie, product_soort)
            VALUES (:prijs, :product_naam, :product_specificaties, :foto, :product_categorie, :product_soort)";
    //query uitvoeren
    $query = $dbh->prepare( $sql );
    $result = $query->execute( array( ':prijs'=>$prijs, ':product_naam'=>$product_naam, ':product_soort'=>$product_soort, 
        ':product_specificaties'=>$product_specificaties, ':foto'=>$foto, ':product_categorie'=>$product_categorie) );

}

I have form to upload properties and a photo of a product to the database. The foto uploads to a map called uploads. But I also want the name of the foto to be inserted into the database. But when I submit I get an error saying the variable $foto is undefined. How to I upload the name of the photo to the database??

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
    • ¥20 关于URL获取的参数,无法执行二选一查询
    • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
    • ¥15 marlin编译错误,如何解决?
    • ¥15 有偿四位数,节约算法和扫描算法
    • ¥15 VUE项目怎么运行,系统打不开
    • ¥50 pointpillars等目标检测算法怎么融合注意力机制
    • ¥20 Vs code Mac系统 PHP Debug调试环境配置
    • ¥60 大一项目课,微信小程序
    • ¥15 求视频摘要youtube和ovp数据集