$_FILES数组为空的原因

今天做上传的文件时候,打印$_files总是为空,查阅了下资料。

发现是 max_file_uploads=0 知道了原因

file_uploads = On
upload_max_filesize = 20M
max_file_uploads = 20

 

转载于:https://www.cnblogs.com/tl542475736/p/5038650.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<?php // 连接数据库 $conn = mysqli_connect("localhost", "tms", "123456", "nut"); // 检查连接是否成功 if (!$conn) { die("数据库连接失败: " . mysqli_connect_error()); }echo "111"; // 处理表单提交 if ($_SERVER["REQUEST_METHOD"] == "POST") { // 获取表单数据 $aoiStep = $_POST['aoi_step']; $defectType = $_POST['defect_type']; $layerCode = $_POST['layer_code']; $type = $_POST['type']; $dpet = $_POST['dpet']; $subcode = $_POST['subcode']; $codeDescription = $_POST['code_description']; $determinationRule = $_POST['determination_rule']; $imagePaths = []; // 存储图片路径的数组 // 处理上传的图片 for ($i = 1; $i <= 5; $i++) { $imageField = "image" . $i; $targetDir = "D:/phpstudy_pro/WWW/192.168.1.16/images"; // 设置上传目录的路径 $fileName = uniqid() . '_' . $_FILES[$imageField]["name"]; // 生成唯一文件名 $targetFile = $targetDir . '/' . basename($fileName); // 将反斜杠替换为正斜杠 $targetFile = str_replace('\\', '/', $targetFile); if (isset($_FILES[$imageField]) && $_FILES[$imageField]["error"] == UPLOAD_ERR_OK && move_uploaded_file($_FILES[$imageField]["tmp_name"], $targetFile)) { $imagePath = $targetFile; } else { $imagePath = ""; } $imagePaths[] = $imagePath; } // 其他图片的处理代码,类似上面的处理方式 $stmt = $conn->prepare("INSERT INTO tms (aoi_step, defect_type, layer_code, type, dpet, subcode, code_description, image1_path, image2_path, image3_path, image4_path, image5_path, determination_rule) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); if (!$stmt) { die("预处理失败: " . $conn->error); } $stmt->bind_param("sssssssssssss", $aoiStep, $defectType, $layerCode, $type, $dpet, $subcode, $codeDescription, $imagePaths[0], $imagePaths[1], $imagePaths[2], $imagePaths[3], $imagePaths[4], $determinationRule); if ($stmt->execute()) { echo "数据插入成功"; } else { echo "数据插入失败: " . $stmt->error; } // 关闭数据库连接 mysqli_close($conn); } ?>我文字内容能够上传到数据库,但是图片无法进行上传
最新发布
07-25
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值