我正在尝试使用Malsup Jquery Form Plugin来制作图像上传器,事实是我没有得到验证的响应。
在验证上我做了多次检查,然后我打印了一些错误,用jquery来获取它并打印一条与这个数字对应的消息(我将把php验证代码放在帖子的末尾。)< / p>
如果我这样做:
$("#formCrearCategoria").ajaxForm({
beforeSend: function(){},
uploadProgress: function(){},
success: function(){},
complete: function(response){
$(".success").html(response.responseText);
}
});
我什么都没得到,所以,response.responseText是空的。
注意:如果我使用没有Jquery Form插件的上传表单(重定向到操作文件)它可以工作。
php验证码是:
<?php
spl_autoload_register(function($nombre){
include_once("../../classes/".$nombre.".php");
});
include_once("../../functions/info.php");
// I check with a boolean to not desorganize all, with multiple if that makes it 0 if it doesn't check the condition.
// At the end I check if todoOk is true, and if it is it means that is ready to go.
$todoOk = 0;
if(isset($_POST["submit"]) && isset($_POST["nombreCategoria"])){
$cCategoria = new Categoria;
$todoOk = 1;
$nombre = $_POST["nombreCategoria"];
if($_FILES["imagenUpload"]["tmp_name"] != ""){ // File upload is not empty...
$fileDir = "uploads/";
$dirAndName = $fileDir . md5(basename($_FILES["imagenUpload"]["name"])) . "." . pathinfo($_FILES["imagenUpload"]["name"], PATHINFO_EXTENSION);
$fileTarget = "../" . $dirAndName;
$imageFileType = pathinfo($_FILES["imagenUpload"]["name"], PATHINFO_EXTENSION);
$urlImagen = getUrl() . "admin/" . $dirAndName;
$check = getimagesize($_FILES['imagenUpload']['tmp_name']);
if($check == FALSE){
$todoOk = 0;
echo "0";
}else{
if($imageFileType !== 'jpg' && $imageFileType !== 'png' && $imageFileType !== 'jpeg'){
$todoOk = 0;
echo "00";
}else{ // It passed through the image file checks, so I upoad it.
if(!move_uploaded_file($_FILES["imagenUpload"]["tmp_name"], $fileTarget)){
echo "001";
}
}
}
}else{ // File input is empty...
$urlImagen = getUrl() . "images/default/thumbnailRect.png";
}
// Chequeo si nombre existe...
$encontro = $cCategoria->selID($nombre);
if($encontro){
echo "000";
$todoOk = 0;
}elseif ($todoOk) {
$db = new MyMysqli;
$consulta = $db->consulta("INSERT INTO categorias(nombreCategoria,imagenCategoria) VALUES ('".$nombre."','".$urlImagen."')");
if($consulta){
echo "1";
}
}
}
?>
非常感谢!
答案 0 :(得分:0)
解决了!
问题是在php验证中我问是否isset($ _ POST ['submit']),并且,由于某种原因,当通过jquery表单插件验证时,提交未设置。
干杯!!