獲得了將產(chǎn)品添加到網(wǎng)上商店的表單。您最多可以上傳10張圖片,最少可以上傳1張圖片。即使將文件名完美地插入到MySQL數(shù)據(jù)庫(kù)中,文件也不會(huì)移動(dòng)到正確的文件夾中。我正在使用共享的Web主機(jī)PHP 5.2,該文件具有寫(xiě)權(quán)限。已經(jīng)與虛擬主機(jī)進(jìn)行過(guò)交談,這不是權(quán)限問(wèn)題。<form action="" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="img1"><b>Image 1</b></label> <input required type="file" class="form-control" name="img1" placeholder="Image 1 (name of the first image, upload it as instructed)"> </div> <div class="form-group"> <label for="img2"><b>Image 2</b></label> <input type="file" class="form-control" name="img2" placeholder="Image 2 (name of the first image, upload it as instructed)"> </div> <div class="form-group"> <label for="img3"><b>Image 3</b></label> <input type="file" class="form-control" name="img3" placeholder="Image 3 (name of the first image, upload it as instructed)"> </div> <div class="form-group"> <label for="img4"><b>Image 4</b></label> <input type="file" class="form-control" name="img4" placeholder="Image 4 (name of the first image, upload it as instructed)"> </div> <div class="form-group"> <label for="img5"><b>Image 5</b></label> <input type="file" class="form-control" name="img5" placeholder="Image 5 (name of the first image, upload it as instructed)"> </div> 獲取文件名稱并將其移動(dòng)到正確文件夾的部分。這些文件沒(méi)有移到旋轉(zhuǎn)木馬文件夾,而是根本沒(méi)有移到任何地方:[Thu Apr 18 18:53:34.249395 2019] [cgi:error] [pid 13994] [client 172.69.130.13:32306] AH01215: PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpOjN6YW' to '../assets/img/carousel/download (2).jpg' in /home/seniorte/public_html/admin/add.php on line 338: /usr/local/cpanel/cgi-sys/ea-php56Error log ^
2 回答

斯蒂芬大帝
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超8個(gè)贊
所以Cherrysoft所說(shuō)的是正確的。它幾乎可以肯定是權(quán)限問(wèn)題,或者不符合您的想法。
我將利用這個(gè)機(jī)會(huì)來(lái)幫助您改進(jìn)代碼。您的示例可以簡(jiǎn)化,以便更輕松地添加10個(gè)以上的圖像,并且更易于維護(hù)。這是您當(dāng)前代碼的更好替代方法:
if(isset($_POST['name'])){
foreach($_FILES as $key => $file) {
move_uploaded_file($file['tmp_name'],"../assets/img/carousel/{$file['name']}");
}
}
這樣,您的代碼就不會(huì)那么重復(fù)了。有一些方法可以進(jìn)一步改善這一點(diǎn),但是我不想被迷住。
- 2 回答
- 0 關(guān)注
- 275 瀏覽
添加回答
舉報(bào)
0/150
提交
取消