I am still can't get any answer of this question. Could any one help me out this issue.
I am trying to send an email with attachment to select person. So, I have filtered the data from database and send email with attachment to selected users.
I have gone through the below answer:
How can I upload files asynchronously?
I have tried the below code of JQuery, Ajax, Controller Action:
<script type="text/javascript">
function SendEmail(){
var checked=0;
jQuery("#action_row").val('delete');
var filename = jQuery("#UserPdf").val();
var audits = '';
$('.checkboxes:checked').each(function(){
checked=1;
audits += this.value+',';
});
var auditsval = audits.slice(0, -1);
//alert(auditsval);
if(checked==1){
var con = confirm('Are you sure you want to send email?');
if(con){
jQuery.ajax({
type: "POST",
url: CommanPath.basePath+'admin/users/send_email',
enctype: 'multipart/form-data',
data: {
file: filename,
ids: auditsval,
},
success: function (data) {
alert("Email sent to selected users ");
}
});
}
}else{
alert("Please select atleast one to send email");
}
}
</script>
UsersCOntroller.php
public function admin_send_email($id = null){
//echo 'here'; die;
$this->layout = 'ajax';
echo '<pre>'; print_r($_FILES); die;
if(isset($this->params['data']['file']) && $this->params['data']['file']){
$filename = time().$this->params['data']['file'];
move_uploaded_file($_FILES['data']['tmp_name']['file']['name'], WWW_ROOT.'uploads/sellingtools/' . $filename);
}
$userids = explode(",", $this->params['data']['ids']);
echo '<pre>'; print_r($userids); die;
}
When I am trying to get uploaded file name, I am getting only file name not getting the tmp_name
.
Anyone can let me know how I can get the tmp_name
and move file to exact path.
Please help.