Tuesday, 27 August 2013

how to pass php controller file to view php file in jquery function codeigniter

how to pass php controller file to view php file in jquery function
codeigniter

HI Am new to Php: i had tried to upload a image file with random
generated nos .then i want to return the uploaded file name in view
php and set in jquery function.here is code uploaded file.
// controller file this file only when i click upload calling
// controller file
function uploadfileview(){
$targeturl = getcwd()."/uploads/";
if($_SERVER['REQUEST_METHOD'] == "POST"){
$checkexisting =
getcwd()."/uploads/".$_FILES['userfile']['name'][0];
$random_number = rand(0,1000000);
//checking the file is existing or not
if(file_exists($checkexisting)) {
if(move_uploaded_file($_FILES['userfile']['tmp_name'][0],
$targeturl.$random_number.'-'.$_FILES['userfile']['name'][0])){ echo
json_encode(array( 'files' =>
$random_number.'-'.$_FILES['userfile']['name'][0], 'post' => $_POST,
'fileurl' =>
getcwd()."/uploads/".$random_number.'-'.$_FILES['userfile']['name'][0] ));
$bb = $random_number.'-'.$_FILES['userfile']['name'][0]; } }else{
if(move_uploaded_file($_FILES['userfile']['tmp_name'][0],
$targeturl.$random_number.'-'.$_FILES['userfile']['name'][0])){ echo
json_encode(array( 'files' =>
$random_number.'-'.$_FILES['userfile']['name'][0], 'post' => $_POST,
'fileurl' =>
getcwd()."/uploads/".$random_number.'-'.$_FILES['userfile']['name'][0] ));
} $data['testing'] = $random_number.'-'.$_FILES['userfile']['name'][0];
return $this->$data('reimbursement'); } // exit; } }
here is the ajax upload form.function.
// for uploaded the file name
jQuery(function(){
var button = $('#uploader-button'), interval;
new AjaxUpload( button, {
action: baseUrl + "expensereimbursement/uploadfileview",
name: 'userfile[]',
multiple: true,
onSubmit : function(file , ext){
// Allow only images. You should add security check on the
server-side.
if (ext && /^(jpg|png|jpeg|pdf)$/.test(ext)){
} else {
// extension is not allowed
$('#bq-reimbursement-form .error-ajax').text('Error:
Invalid File
Format').css('color','red').show().fadeOut(5000);
// cancel upload
return false;
}
// change button text, when user selects file
button.text('Uploading');
// If you want to allow uploading only 1 file at time,
// you can disable upload button
this.disable();
// Uploding -> Uploading. -> Uploading...
interval = window.setInterval(function(){
var text = button.text();
if (text.length < 13){
button.text(text + '.');
} else {
button.text('Uploading');
}
}, 200);
},
onComplete: function(file, response){
button.text('Upload');
window.clearInterval(interval);
// enable upload button
this.enable();
var obj = $.parseJSON(response);
if(obj.error){
$('#bq-reimbursement-form .error-ajax').text('Error: File
Already Exist!').css('color','red').show().fadeOut(5000);
}else {
var url = "https://docs.google.com/viewer?url=" +
obj.fileurl;
var html = '<li><input type="text" name="imageName[]"
value="'+file +'" class="display-type" ><a
class="filenames" target="_blank" href="'+url+'">'+file
+'</a><span class="close-button
display-type">x</span></li>';
$('#upload-file-bq .files').append(html);
}
}
});
});
var html = '<li><input type="text" name="imageName[]" value="'+file
+'" class="display-type" ><a class="filenames" target="_blank"
href="'+url+'">'+file +'</a><span class="close-button
display-type">x</span></li>';
// file = my uploaded file name to be return from controller.
here file only i want to return the uploaded file name can any one
help me please.

No comments:

Post a Comment