我正在尝试拆分上传到ajax方法的图像文件。所有的html和JS都在一个文件中,然后我组成了一个包含所有PHP的PHP文件。我正在努力的是,我不确定如何将图像文件信息发送到php文件,然后如何使其余的php照常工作。截至目前,这行代码$p_img = $_POST['file'];遇到了未定义的索引错误。但是,即使正在填充该文件,我也不确定在分离的文件中是否可以正常使用。无论如何,我可以将第一个PHP函数保留UploadFile在带有HTML和JS的文件中,然后将该函数发送到PHP文件中吗?如果没有,我该怎么办?的HTML<form action="" method="POST" id="projectForm" enctype="multipart/form-data"> <label>Project Name</label> <input type="text" class="input block" name="p_name"> <label>Project Img</label> <input type="file" id="file" name="file" class="file-input block"> <button id="submit">Submit Project</button></form>JS$('#projectForm').validate({ ignore: [], rules: { p_name: { required: true, minlength: 5 }, p_alt: { required: true, minlength: 2 } }, messages: { p_name: { required: "Please enter the project name", minlength: "The project name is too short" }, p_alt: { required: "Please enter the alt text", minlength: "Your alt text is too short" } }, submitHandler: function (form, e) { e.preventDefault(); var formData = new FormData(form); category = $(this).data('category'); console.log(category); $.ajax({ url: '/php/projectSend.php', type: 'POST', data: formData, success: function (data) { console.log(data); }, contentType: false, processData: false, error: function (xhr, textStatus, errorThrown) { alert(textStatus + " | " + errorThrown); alert('There are currently no project images for this selection'); } }); } });
- 2 回答
- 0 关注
- 169 浏览
添加回答
举报
0/150
提交
取消