Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to pass php controller file to view php file in jquery function codeigniter
    text
    copied!<p>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.</p> <pre><code> // 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' =&gt; $random_number.'-'.$_FILES['userfile']['name'][0], 'post' =&gt; $_POST, 'fileurl' =&gt; 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' =&gt; $random_number.'-'.$_FILES['userfile']['name'][0], 'post' =&gt; $_POST, 'fileurl' =&gt; getcwd()."/uploads/".$random_number.'-'.$_FILES['userfile']['name'][0] )); } $data['testing'] = $random_number.'-'.$_FILES['userfile']['name'][0]; return $this-&gt;$data('reimbursement'); } // exit; } } </code></pre> <p>Here is the ajax upload form.function.</p> <pre><code>// 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 &amp;&amp; /^(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 -&gt; Uploading. -&gt; Uploading... interval = window.setInterval(function(){ var text = button.text(); if (text.length &lt; 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 = '&lt;li&gt;&lt;input type="text" name="imageName[]" value="'+file +'" class="display-type" &gt;&lt;a class="filenames" target="_blank" href="'+url+'"&gt;'+file +'&lt;/a&gt;&lt;span class="close-button display-type"&gt;x&lt;/span&gt;&lt;/li&gt;'; $('#upload-file-bq .files').append(html); } } }); }); var html = '&lt;li&gt;&lt;input type="text" name="imageName[]" value="'+file +'" class="display-type" &gt;&lt;a class="filenames" target="_blank" href="'+url+'"&gt;'+file +'&lt;/a&gt;&lt;span class="close-button display-type"&gt;x&lt;/span&gt;&lt;/li&gt;'; // file = my uploaded file name to be return from controller. </code></pre> <p>Here file only i want to return the uploaded file name can any one help me please.is this possible get the value in jquery.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload