简体   繁体   English

jQuery提交表单和php

[英]jQuery submit form and php

I'm making a upload form and have chosen to do this with jQuery. 我正在制作一个上传表单,并选择使用jQuery。 The file gets uploaded but not into the desired folder, so im not parsing the data correct from the upload form to the process. 该文件将被上载,但不会放入所需的文件夹中,因此无法正确解析从上载表单到流程的数据。

upload.php upload.php的

<script>
$(document).ready(function()
{

var settings = {
    url: "upload_process.php",
    method: "POST",
    allowedTypes:"jpg,jpeg,png",
    fileName: "myfile",
    galleryName: "<?php echo $gallery->folder; ?>",
    multiple: true,
    onSuccess:function(files,data,xhr)
    {
        $("#status").html("<font color='green'>Upload is success</font>");
    },
    onError: function(files,status,errMsg)
    {       
        $("#status").html("<font color='red'>Upload is Failed</font>");
    }
}

$("#mulitplefileuploader").uploadFile(settings);

});
</script>

upload_process.php upload_process.php

$galleryName = $_POST["galleryName"];
$output_dir = "media/images/".$galleryName."/";

if(isset($_FILES["myfile"])) {
    $ret = array();
    $error = $_FILES["myfile"]["error"];
    {
        /* Single File */
        if(!is_array($_FILES["myfile"]['name'])) {
            $fileName = $_FILES["myfile"]["name"];
            move_uploaded_file($_FILES["myfile"]["tmp_name"], $output_dir . $_FILES["myfile"]["name"]);
            $ret[$fileName] = $output_dir.$fileName;
        /* Multiple files */    
        } else {
            $fileCount = count($_FILES["myfile"]['name']);
            for($i=0; $i < $fileCount; $i++) {
                $fileName = $_FILES["myfile"]["name"][$i];
                $ret[$fileName] = $output_dir.$fileName;
                move_uploaded_file($_FILES["myfile"]["tmp_name"][$i],$output_dir.$fileName );
            }
        }
    }
    echo json_encode($ret);
}

The file is uploaded to media/images/ and can't see why the $galleryName is not set? 该文件已上传到media / images /,看不到为什么未设置$ galleryName?

The parameter passing to the script does not seem to be right. 传递给脚本的参数似乎不正确。 You did not specify the exact jQuery plugin that is being used, so the below example might not work, but if so, it should at least give You a good hint about what to look for in the plugin documentation 您没有指定要使用的确切jQuery插件,因此下面的示例可能不起作用,但是,如果这样,它至少应该为您提供一个有关在插件文档中查找内容的好提示。

Please remove the line 请删除行

galleryName: "<?php echo $gallery->folder; ?>",

And replace with lines 并换成线条

enctype: "multipart/form-data", // Upload Form enctype.
formData: { galleryName: "<?php echo $gallery->folder; ?>" },

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM