为了账号安全,请及时绑定邮箱和手机立即绑定

图片上传器非常适合插入表单,但不适用于更新表单

图片上传器非常适合插入表单,但不适用于更新表单

PHP
慕容森 2022-12-30 16:53:43
我知道已经有很多类似的问题,我提前为添加到文件中而道歉,但我做研究的时间有点短,我需要快速帮助。我正在尝试完成一项逾期的作业,并且我的图片上传功能在我添加产品时运行良好,但在我更新产品时却无法正常运行。我不知道为什么。我更新图像的代码在这里:require_once 'file-util.php'    // Check if the file exists before setting it    if (isset($_FILES['imageFile1'])) {        // Retrieve the name of the file based on what it was called on the client computer        $filename = $codeInput . '.png';        // Make sure the filename exists         if (!empty($filename)) {            // Store the temporary location of where the file was stored on the server            $sourceLocation = $_FILES['imageFile1']['tmp_name'];            // Build the path to the images folder and use the same filename as before            $targetPath = $image_dir_path . DIRECTORY_SEPARATOR . $filename;            // Move file from temp directory to images folder            move_uploaded_file($sourceLocation, $targetPath);        }    }这与我在 insert_product 文件中的代码完全相同。我的 file_util 在这里:$image_dir = 'images';$image_dir_path = getcwd() . DIRECTORY_SEPARATOR . $image_dir;其他一切都运行良好,但就是这个小东西似乎什么也没做,所以在我看来,我缺少一些细节才能在 update_product 中工作。我还需要做些什么才能让它发挥作用,还是我不知道的其他事情?编辑:原来我只是忘记在我的 add_product_form 中设置加密类型。如果其他人有这个愚蠢的问题,请仔细检查靠近身体顶部的表格:<form action="insert_product.php" method="post"              id="add_product_form"              enctype="multipart/form-data">
查看完整描述

2 回答

?
噜噜哒

TA贡献1784条经验 获得超7个赞

您需要检查您的更新表单标签是否具有正确的 enctype 属性值...并且请注意对上传的文件使用更多验证,您对文件名是否存在的检查将始终为真,因为您正在设置一个值它在上一行。



查看完整回答
反对 回复 2022-12-30
?
摇曳的蔷薇

TA贡献1793条经验 获得超6个赞

显然,我的代码是正确的,但我只是忘了在 update_product_form.php 中加入“enctype="multipart/form-data"。



查看完整回答
反对 回复 2022-12-30
  • 2 回答
  • 0 关注
  • 55 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信