here is the code. showing alert as object form data. My plan is to send the file name through ajax and upload the file in proper path using php. In the first step i want to send the file using jquery. i stuckup here
<script>
$(document).on('click','#btn_photo',function(){
var fd = new FormData();
var files = $('#photo')[0].files;
// Check file selected or not
if(files.length > 0 )
{
fd.append('file',files[0]);
alert(fd);
$.ajax({
url: 'ajax_upload.php',
type: 'post',
data: fd,
contentType: false,
processData: false,
success: function(response)
{
if(response != 0)
{
alert(response);
}
else
{
alert('file not uploaded');
}
}
});
}
else
{
alert("Please select a file.");
}
});
HTML form is given below:
<form method="post" enctype="multipart/form-data">
<div class="panel panel-info col-lg-4">
<div class="panel-heading"><b>UPLOADING PHOTO</b></div>
<div class="panel-body">
<div class="form-group" id="notext3">
<div class='preview'>
<img src="" id="photo_disp" width="100" height="100">
</div>
<label for="photo">Photo Upload (size < 50Kb only jpg)</label>
<div class="input-group">
<span class="input-group-addon transparent"><span class="glyphicon
glyphicon-cloud-upload"></span></span>
<input type="file" name="photo" id="photo" class="form-control" accept=".jpeg,.jpg" required/>
</div>
</div>
</div>
<div class="text-center">
<button type="submit" id="btn_photo" name="submit" class="btn btn-info btn-sm">Upload Photo</button>
</div><br>
</div>
</form>