正如標(biāo)題所說(shuō),有人知道為什么圖片沒(méi)有上傳嗎?我正在嘗試制作一個(gè) propic 圖片上傳頁(yè)面,但圖片沒(méi)有上傳。這是 HTML 表單:<form enctype="multipart/form-data" method="POST" action="../php/modifica-profilo.php"><!-- other inputs --><div class="form-group"> <label>Immagine profilo</label> <input type="file" name="propic" class="form-control-file" accept="image/x-png,image/jpeg"> <small class="form-text text-muted">Solo immagini .png e .jpg - Dimensione massima 4 MB</small></div><div class="form-group"> <button class="btn btn-primary btn-block" type="submit" name="dettagliBtn">Salva modifiche</button></div>這是 php 腳本部分“modifica-profilo.php”:if(!empty($_POST['propic'])){ $dimensioneFile = $_FILES['propic']['size']; $tipoFile = $_FILES['propic']['type']; $tmp_name = $_FILES['propic']['tmp_name']; $dir = "../img/propic-utenti/"; $estensione = image_type_to_extension(IMAGETYPE_PNG); $estensione = image_type_to_extension(IMAGETYPE_JPEG); $propic = md5($uid).$estensione; if($dimensioneFile > 4000000){ echo "Il file è troppo grande"; }else{ move_uploaded_file($tmp_name,$dir.$propic); } }else{ $prendoPropic = "SELECT propic FROM clienti WHERE id='$uid';"; $rpp = $conn->query($prendoPropic); $p = $rpp->fetch_assoc(); if($p['propic'] == "p-default.png"){ $propic = "p-default.png"; }else{ $propic = $p['propic']; } } $aggiornodb = "UPDATE clienti SET cognome='$cognome', nome='$nome', email='$email', propic='$propic' WHERE id='$uid';"; $risultato = $conn->query($aggiornodb);
1 回答

子衿沉夜
TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超3個(gè)贊
這是因?yàn)椋?_POST['propic']永遠(yuǎn)是空的,這應(yīng)該是$_FILES['propic']
你最好用這個(gè)
if(!empty($_POST['dettagliBtn'])){
//since you only have 1 data on $_POST which is the button. Because you have given it a name attribute.
而不是這個(gè)
if(!empty($_POST['propic'])){
// this will always get false
還要確保提交按鈕位于您的表單內(nèi)。
- 1 回答
- 0 關(guān)注
- 109 瀏覽
添加回答
舉報(bào)
0/150
提交
取消