亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

圖片上傳器非常適合插入表單,但不適用于更新表單

圖片上傳器非常適合插入表單,但不適用于更新表單

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 關注
  • 98 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號