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); }
为什么表单提交后photo字段显示成Array而不是图片上传后的路径?文件是能上传提交上去的,那个地方出了问题还请高手赐教!!!!
------解决方案--------------------
与字段 photo 对应的是变量 $photo
而
$photo = $upfile;
且
$upfile = $_FILES['photo'];
是一个数组
你应该将 $file_path . $new_name 存入 photo 字段
但 $file_path 中的 "../" 可能会给后期使用带来麻烦

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver CS6
Visual web development tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Zend Studio 13.0.1
Powerful PHP integrated development environment
