[英]how to send image file through ajax load() function and insert in mysql db display in div through php
This is form i am sending image file to the upload.php
script file and image file should display in the 'onsuccessmsg' div 这是我将图像文件发送到
upload.php
脚本文件的形式,图像文件应显示在'onsuccessmsg'div中
<form action="upload.php" method="POST" id="uploadform">
<input type="file" file="file" id="file_to_send"/>
<input type="submit" value="Upload"/><br/><br/>
Message :
<div id="onsuccessmsg" style="border:5px solid #CCC;padding:15px;"></div>
</form>
This is the JavaScript code: 这是JavaScript代码:
<script>
$(document).ready(function(){
$("#uploadform").on('submit',function(){
$("#onsuccessmsg").load("upload.php",{},function(res){
});
});
});
</script>
This is the upload.php
file: 这是
upload.php
文件:
<?php
if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
$name = $_FILES['file']['name'];
$size = $_FILES['file']['size'];
$tmp = $_FILES['file']['tmp_name'];
if(move_uploaded_file($tmp, "./uploads/".$imgn))
{
echo "File Name : ".$_FILES['file']['name'];
echo "<br/>File Temporary Location : ".$_FILES['file']['tmp_name'];
echo "<br/>File Size : ".$_FILES['file']['size'];
echo "<br/>File Type : ".$_FILES['file']['type'];
echo "<br/>Image : <img style='margin-left:10px;' src='uploads/".$imgn."'>";
}
}
?>
Onsubmit the form how to send the name and id values to the upload.php
file and echoing the image file in the onsuccessmsg
div, I am confused, please help me. Onsubmit表单如何将名称和ID值发送到
upload.php
文件并在onsuccessmsg
div中回显图像文件,我很困惑,请帮助我。
You can use iframe for such upload of image with jquery... 您可以使用iframe通过jquery这样上传图片...
$(document).ready(function()
{
$("#input_for_image_upload").change(function()
{
$("#img_upload").submit();
});
});
You will get the image name through this code 您将通过此代码获得图像名称
$('#submit').click(function()
{
var str=$("#image").val();
var arr=str.split("\\");
var image=arr[2];
alert(image);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.