Monday 9 September 2013

How to use PHP copy in javascript

How to use PHP copy in javascript

What I want to do is when I click a button and copy the file from
different directory to my directory
here is my code
<a href="" file-name="<?php echo $record_filename; ?>" title="download"
class="download"><i class="icon-play"></i></a>
<script type="text/javascript">
$(document).ready(function() {
$('.download').click(function(e) {
var file = '/var/spool/asterisk/monitor/';
var newfile = '/var/www/html/qm/file/';
var file_name = $(this).attr('file-name');
var old_dir = file + file_name;
var new_dir = newfile + file_name;
######## Stuck From Here #############
<?php copy(old_dir, new_dir); ?>
var url = config.base_url + 'file',
e.preventDefault();
window.location.href = url;
});
});
</script>
Forgive my mistake
here is my solution
$('.download').click(function(e) {
var file_name = $(this).attr('file-name');
download(file_name);
});
function download(file_name)
{
$.ajax({
type: "POST",
async : false,
url: config.base_url + 'voice_logger/download',
dataType: 'json',
data : {
file_name : file_name,
},
success : function(data) {
if(data=='success')
{
location.reload();
}
else if(data=='error')
{
alert('Error.');
}
},
error : function(XMLHttpRequest, textStatus, errorThrown) {
alert(XMLHttpRequest + " : " + textStatus + " : " + errorThrown);
}
});
}
Any idea how to do copy in javascript using php?
thanks

No comments:

Post a Comment