Home > Backend Development > PHP Tutorial > php下传字段保存到mysql

php下传字段保存到mysql

WBOY
Release: 2016-06-13 13:10:08
Original
817 people have browsed it

php上传字段保存到mysql

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->            if($dsql->ExecuteNoneQuery($sql))
            {
                //文件存储路径
                $file_path="../upload/";
                //664权限为文件属主和属组用户可读和写,其他用户只读
                if(is_dir($file_path)!=TRUE) mkdir($file_path,0664);
                //定义允许上传的文件扩展
                $ext_arr = array("gif", "jpg", "jpeg", "png", "bmp", "txt", "zip", "rar");
                //获得文件扩展名
                $temp_arr = explode(".", $_FILES["photo"]["name"]);
                $file_ext = array_pop($temp_arr);
                $file_ext = trim($file_ext);
                $file_ext = strtolower($file_ext);
                //获取上传文件的信息赋给变量
                $upfile = $_FILES['photo'];
                $photo = $upfile;
                //以时间戳重命名文件
                $new_name = time().".".$file_ext;
                //将文件移动到存储目录下
                move_uploaded_file($_FILES["photo"]["tmp_name"],"$file_path" . $new_name);
                //向数据表写入文件存储信息以便管理
                foreach($Items as $key=>$val)
                {
                    $val['price'] = str_replace(",","",$val['price']);
                    $dsql->ExecuteNoneQuery("INSERT INTO `#@__shops_products` (`aid`,`oid`,`userid`,`title`,`price`,`buynum`)
                    VALUES ('$val[id]','$OrdersId','$userid','$val[title]','$val[price]','$val[buynum]');");
                }
                $sql = "INSERT INTO `#@__shops_userinfo` (`userid`,`oid`,`consignee`,`address`,`zip`,`tel`,`email`,`qq`,`cphm`,`t1`,`t2`,`period`,`des`,`dabh`,`photo`,`scanning`)
                 VALUES ('$userid','$OrdersId','$postname','$address','$zip','$tel','$email','$qq','$cphm','$t1','$t2','$period','$des','$dabh','$photo','$scanning');
                ";
                $dsql->ExecuteNoneQuery($sql);
            }
            else
            {
                ShowMsg("更新订单时出现错误!".$dsql->GetError(),"-1");
                exit();
            }
        } else {
            $sql = "UPDATE `#@__shops_orders`
            SET `cartcount`='$CartCount',`price`='$priceCount',`ip`='$ip',`stime`='$stime',pid='$pid',paytype='$paytype',dprice='$dprice',priceCount='$lastpriceCount'
            WHERE oid='$OrdersId' AND userid='$userid' ;";
            if($dsql->ExecuteNoneQuery($sql))
            {
                $sql = "UPDATE `#@__shops_userinfo`
                SET `consignee`='$postname',`address`='$address',`zip`='$zip',`tel`='$tel',`email`='$email',`qq`='$qq',`cphm`='$cphm',`t1`='$t1',`t2`='$t2',`period`='$period',`des`='$des',`dabh`='$dabh',`photo`='$photo',`scanning`='$scanning'
                WHERE oid='$OrdersId';";
                $dsql->ExecuteNoneQuery($sql);
            }
            else
            {
                echo $dsql->GetError();
                exit;
            }
            unset($sql);
        }
Copy after login


为什么表单提交后photo字段显示成Array而不是图片上传后的路径?文件是能上传提交上去的,那个地方出了问题还请高手赐教!!!!

------解决方案--------------------
与字段 photo 对应的是变量 $photo

$photo = $upfile;

$upfile = $_FILES['photo'];
是一个数组

你应该将 $file_path . $new_name 存入 photo 字段
但 $file_path 中的 "../" 可能会给后期使用带来麻烦
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template