正如标题所说,有人知道为什么图片没有上传吗?我正在尝试制作一个 propic 图片上传页面,但图片没有上传。这是 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贡献1828条经验 获得超3个赞
这是因为,$_POST['propic']永远是空的,这应该是$_FILES['propic']
你最好用这个
if(!empty($_POST['dettagliBtn'])){
//since you only have 1 data on $_POST which is the button. Because you have given it a name attribute.
而不是这个
if(!empty($_POST['propic'])){
// this will always get false
还要确保提交按钮位于您的表单内。
- 1 回答
- 0 关注
- 79 浏览
添加回答
举报
0/150
提交
取消