[英]Upload 7 files using 7 separate file input tag using AJAX or JQuery or JavaScript in php
My client wants to upload the file without using <form>
tag & also without using submit button in php. 我的客户想要上传文件而不使用
<form>
标记,也不想使用php中的Submit按钮。
I know how to upload the file in PHP but I really don't know how to do it without using <form>
tag. 我知道如何用PHP上传文件,但我真的不知道如何在不使用
<form>
标记的情况下进行上传。
He only wants us to use <button>
tag. 他只希望我们使用
<button>
标记。 How to do it without using <form>
tag. 如何在不使用
<form>
标记的情况下进行操作。 I've searched everywhere but I didn't find any solutions to it. 我到处搜索过,但找不到任何解决方案。 Here is my HTML code:
这是我的HTML代码:
file1
<input type="file" id="file1" name="file1" accept="*.jpg"><hr>
file2
<input type="file" id="file2" name="file2" accept="*.jpg"><hr>
file3
<input type="file" id="file3" name="file3" accept="*.jpg"><hr>
file4
<input type="file" id="file4" name="file4" accept="*.jpg"><hr>
file5
<input type="file" id="file5" name="file5" accept="*.jpg"><hr>
file6
<input type="file" id="file6" name="file6" accept="*.jpg"><hr>
file7
<input type="file" id="file7" name="file7" accept="*.jpg"><hr>
<button id='upload' name='upload'>Upload</upload>
Please help me I want it very badly. 请帮助我,我非常想要它。 Please don't discard it as saying not enough work done.
请不要说没有完成的工作而放弃它。 Thank you.
谢谢。
https://blueimp.github.io/jQuery-File-Upload/ https://blueimp.github.io/jQuery-File-Upload/
You need to use jquery form library 您需要使用jQuery表单库
first downlaod the jquery form library for form submit 首先将jQuery表单库下载为表单提交
html code like : 像这样的html代码:
<div class="row">
<div class="col-md-4 col-xs-12">
<div class="form-group">
<form id="imageform" method="post" enctype="multipart/form-data" action='ajaximage.php'>
Upload your image <input type="file" name="photoimg" id="photoimg" />
</form>
<div id='preview'>
</div>
and the jquery/js code like : 和类似的jquery / js代码:
document.getElementById("photoimg").onchange = function()
{
$("#preview").html('');
$("#preview").html('<img src="loader.gif" alt="Uploading...."/>');
$("#imageform").ajaxForm({
target: '#preview'
}).submit();
};
and ajaximage.php like 和ajaximage.php一样
<?php
//include('db.php');
session_start();
$session_id='1'; //$session id
$path = "photo/";
$valid_formats = array("jpg", "png", "gif", "bmp","JPG","PNG","GIF");
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST")
{ $name = $_FILES['photoimg']['name'];
$size = $_FILES['photoimg']['size'];
if(strlen($name))
{
list($txt, $ext) = explode(".", $name);
if(in_array($ext,$valid_formats))
{
if($size<(1024*1024))
{
$actual_image_name = time().substr(str_replace(" ", "_", $txt), 5).".".$ext;
$tmp = $_FILES['photoimg']['tmp_name'];
if(move_uploaded_file($tmp, $path.$actual_image_name))
{
echo "<img src='photo/".$actual_image_name."' class='preview'>";
echo "<input type='hidden' name='imageName' value='".$actual_image_name."' id='imageName'>";
}
else
echo "failed";
}
else
echo "Image file size max 1 MB";
}
else
echo "Invalid file format..";
}
else
echo "Please select image..!";
exit;
}
?>
您可以使用AJAX,在单击按钮时调用一个函数,然后使用AJAX将数据发送到服务器而无需提交表单。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.