我通过克隆我工作中的其他网站创建了一个新网站,但我没有创建或编写此网站。
所以,我的问题是:该网站正在运行,但图片上传无效,我没有想到发生了什么。我尝试了很多东西来解决这个问题,例如变量中的var_dump来尝试调试。这是代码:
<? require_once("header.php"); ?>
<? require_once("menu.php"); ?>
<? require_once("ConnFile.php"); ?>
<?
if ($_GET["acao"] == "excluir")
{
$Tabela = "BannerHome";
$TabelaChave = "idBanner";
if( is_numeric($_GET["k"]))
{
$txtIdProduto = $_GET["k"];
$acao = ("UPDATE $Tabela SET Imagem". $_GET["I"] . " = '' WHERE $TabelaChave = $txtIdProduto ");
if(mysqli_query($link, $acao)) {
echo '<div class="alert alert-success alert-dismissible"" role="alert"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> Registro removido com sucesso</div>';
} else {
echo '<div class="alert alert-danger alert-dismissible"" role="alert"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> Não foi possível remover o registro. </div>';
}
}
}
?>
<?
$id = 0;
if( is_numeric($_GET["k"])) {
$id = $_GET["k"];
}
$DadosProduto = mysqli_fetch_array( mysqli_query($link, "SELECT * FROM BannerHome WHERE idBanner = " . $id ));
?>
<? if( $DadosProduto["Imagem" . $_GET["I"]] == "" ) { print '<div class="alert alert-warning alert-dismissible"" role="alert"> <button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">×</span><span class="sr-only">Close</span></button> Este banner ainda não possui imagem cadastrada. </div>'; } ?>
<?
?>
<link href="upload/assets/css/style.css" rel="stylesheet" />
<h4>Banner home<small> / Imagems / <?=$DadosProduto["Titulo"]; ?> </small></h4>
<form class="form-horizontal" role="form" id="upload" action="upload/uploadHome.php?k=<?=$id; ?>&I=<?=$_GET['I']; ?>" method="post" enctype="multipart/form-data">
<div id="drop">
<pre>
<center>
Arreste as imagens (Fundo 1920x400, Superior 420x40)
<br>
ou
<br>
<a class="btn btn-primary btn-lg" >Selecione as imagens</a>
<input type="file" name="upl" multiple />
</div>
</center>
</pre>
<ul>
<!-- The file uploads will be shown here -->
</ul>
<div style="clear:both";>
<?
var_dump($DadosProduto);
if($DadosProduto["Imagem" . $_GET["I"]] != "" ) {
print '<div class="panel panel-default" style="width:145px; float:left; margin-right:4px;">';
print ' <div class="panel-body">';
print ' <img src="../gdThumb.php?imagem=' . $DadosProduto["Imagem" . $_GET["I"]] . '" alt="" class="img-thumbnail">';
print ' </div>';
print ' <div class="panel-footer"><center><a href="?acao=excluir&k='. $DadosProduto["idBanner"] .'&I='. $_GET["I"] .'"><span class="glyphicon glyphicon-remove"></span> Remover</a></center></div>';
print '</div> ';
}
?>
</div>
</form>
<script src="upload/assets/js/jquery.knob.js"></script>
<!-- jQuery File Upload Dependencies -->
<script src="upload/assets/js/jquery.ui.widget.js"></script>
<script src="upload/assets/js/jquery.iframe-transport.js"></script>
<script src="upload/assets/js/jquery.fileupload.js"></script>
<!-- Our main JS file -->
<script src="upload/assets/js/script.js"></script>
<? require_once("footer.php"); ?>
我认为问题出在表单动作
中<form class="form-horizontal" role="form" id="upload" action="upload/uploadHome.php?k=<?=$id; ?>&I=<?=$_GET['I']; ?>" method="post" enctype="multipart/form-data">
因为上传文件夹和php文件也存在。但是当表单调用此操作时,没有任何反应。我试着用:var_dump,die(),echo,很多东西都看到了简单的反应。我无法调试uploadHome.php,我不知道为什么。
connFile.php正在运作
所以,我需要调用此页面来存储我的图像,而页面不会调用。这是uploadHome.php:
<? require_once("../ConnFile.php"); ?>
<?php
$idProduto = $_GET["k"];
// A list of permitted file extensions
$allowed = array('png', 'jpg', 'gif','zip');
if(isset($_FILES['upl']) && $_FILES['upl']['error'] == 0){
$extension = pathinfo($_FILES['upl']['name'], PATHINFO_EXTENSION);
if(!in_array(strtolower($extension), $allowed)){
echo '{"status":"error"}';
exit;
}
$arquivo = 'BannerHome_'. $_GET["k"] . '_' . rand(1,1500) . '-' . md5($_FILES['upl']['name']) . "." . $extension;
if(move_uploaded_file($_FILES['upl']['tmp_name'], '../../img/produto/'. $arquivo)){
mysqli_query($link, "UPDATE BannerHome SET Imagem". $_GET['I'] ." = '$arquivo' WHERE idBanner = " . $_GET["k"]);
echo '{"status":"success"}';
exit;
}
}
echo '{"status":"error"}';
exit;
我非常感谢您提供给我的任何信息,因为我不知道该怎么做。
答案 0 :(得分:0)
我得到了许可错误。我看不到错误,因为ajax没有向我显示任何内容。
如果有人遇到类似问题,检查和更改目录权限可能有所帮助。