Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 103
  • Last Modified:

Could you point a way on how to obtain the a file's name to be presented on a Codeigniter view?

Hi Experts

Could you point a way on how to obtain the a file's name to be presented on a view?

The file name and complete path remain on a table column.

My tentative is:

<script type="text/javascript">
$(function () {
	  var serv = $(this).parents('.modal').find('.id_reclamacao').val();
        
    	$.ajax({
		  // Codeigniter Controller
    		url: baseurl+'reclamacao/get/' + serv,
    		type: 'post',
    		cache: false,
    		contentType: false,
    		processData: false,
    		dataType: 'json',
    		data: serv,
    		success: function (data) {
    		var anexo = data['anexo'];
    	    
            $('<p/>').text(anexo).appendTo(document.body);
          
    		},
    		error: function(jqXHR) {
    			bootbox.alert(jqXHR.responseText);
    		}
    	});	
});
</script>

Open in new window


The table's column  that contains the file's name to be presented.

 

Could you check and possibly suggest something?

Thanks in advance
0
Eduardo Fuerte
Asked:
Eduardo Fuerte
  • 14
  • 10
1 Solution
 
Julian HansenCommented:
I think the image you posted relates to your other question.

Can you show us the HTML for the table.
0
 
Eduardo FuerteAuthor Commented:
Hi

Please desconsider image img_EE_111016_005.png - I forgot to delete it. The relevant imageto this question is appearing.
0
 
Eduardo FuerteAuthor Commented:
Here is the code:

The relevant part I'm trying to implement starts at  line 560
codigo_tela_131016.php
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Julian HansenCommented:
Could you point a way on how to obtain the a file's name to be presented on a view?
Which filename are we looking for ?
0
 
Eduardo FuerteAuthor Commented:
Julian


The relevant picture was eliminated  with the other ...

img004
The above jQuery I posted must retrive the database column "anexo"  value and simply present it  when the view is presented.
0
 
Julian HansenCommented:
I understand - but I need to see where that column is in the HTML. The only reference I can find in your code to anexo is this
                                    <!-- Anexo -->
                                    <hr>
                                    <div class='row'>
                                        <div class="col-xs-12 mb20">
                                            <label for="anexo" class="field-label text-muted mb10">Anexo</label>
                                            <input name="fileuser" id="fileuser" type="file" class="form-control gui-input br-light light" placeholder="">
                                        </div>
                                    </div>

Open in new window

Which is a file input and where the label Anexo is capitalised - where as in the image in your previous post it is a small letter.
Where is the html that generates the image you posted?
0
 
Eduardo FuerteAuthor Commented:
The jQuery above runs ok to download the file when the "Download file" button is clicked.

What I need is to present the filename to be downloaded previously - making it possible to disable the button if the column anexo has no content, and to present the content if the column has a content.
0
 
Eduardo FuerteAuthor Commented:
Our messages crossed... just a moment.
0
 
Eduardo FuerteAuthor Commented:
The html anexo that you saw refers to upload feature:


img002
  <!-- Anexo -->
<hr>
<div class='row'>
	<div class="col-xs-12 mb20">
		<label for="anexo" class="field-label text-muted mb10">Anexo</label>
		<input name="fileuser" id="fileuser" type="file" class="form-control gui-input br-light light" placeholder="">
	</div>
</div>

<script type="text/javascript">
	$(function () {
		$('#fileupload').fileupload({
			dataType: 'json',
			done: function (e, data) {
				$.each(data.result.files, function (index, file) {
					$('<p/>').text(file.name).appendTo(document.body);
				});
			}
		});
	});
</script>

Open in new window


What I need  is to present the "anexo"  previously uploaded  or disable the "Download" if no file was uploaded when editing...
0
 
Julian HansenCommented:
Yes I understand but I don't know what the HTML for the anexo file is displayed.
0
 
Eduardo FuerteAuthor Commented:
It's displayed just to point that a file exists to be downloaded and what is its name.

In the picture "name of the file to be downloaded"  (previously uploaded)
0
 
Eduardo FuerteAuthor Commented:
And it just displays the db table's column content obtained in jQuery.
0
 
Julian HansenCommented:
Ok, but as I understand it your question is how to get the filename out of that bit of HTML - and if we can't see the HTML that contains the filename I am not sure how to proceed.
0
 
Eduardo FuerteAuthor Commented:
Isn't it possible to print directly in the document body ?
like:

$('<p/>').text(anexo).appendTo(document.body);

Open in new window

0
 
Julian HansenCommented:
Yes, but I thought you wanted this
Could you point a way on how to obtain the a file's name to be presented on a view?
The file name and complete path remain on a table column.
I interpret that to mean the filename is somewhere on the page (remain on a table column) and you want to retrieve it.
0
 
Eduardo FuerteAuthor Commented:
Oh... I understand now your doubt.

 it's not a HTML table -  it's a Database table that just has the value I need in the column called anexo.

This picture represents DB table column value:
img004
And this code - not  yet working, to retrieve column values:
<script type="text/javascript">
$(function () {
	  var serv = $(this).parents('.modal').find('.id_reclamacao').val();
        
    	$.ajax({

		  // Codeigniter Controller
    		url: baseurl+'reclamacao/get/' + serv,
    		type: 'post',
    		cache: false,
    		contentType: false,
    		processData: false,
    		dataType: 'json',
    		data: serv,
    		success: function (data) {
    		var anexo = data['anexo'];
    	    
          // Presents the column value
            $('<p/>').text(anexo).appendTo(document.body);
          
    		},
    		error: function(jqXHR) {
    			bootbox.alert(jqXHR.responseText);
    		}
    	});	
});
</script>

Open in new window

(this code is adapted from the download feature of the modal view)

Could you suggest what's needed?
0
 
Julian HansenCommented:
Ok, I understand - is  the AJAX call correctly returning the data
success: function (data) {
  var anexo = data['anexo'];
  console.log(data); // WHAT DOES THIS OUTPUT
  // Presents the column value
  $('<p/>').text(anexo).appendTo(document.body);
},

Open in new window

0
 
Eduardo FuerteAuthor Commented:
I don't know if I correctly coded and where is the correct place to post this jQuery:

The value must be presented just bellow "Reembolso" accordingly to:
img003
So, in the middle of HTML:
....
<div class="col-xs-4 mb20 reembolso" style="display: none;">
	<label for="reembolso" class="field-label text-muted mb10">Reembolso</label>
	<div class="input-group">
		<span class="input-group-addon">
			<i class="fa fa-money c-gray"></i>
		</span>
		<span class="validar">
			<input type="text" name="reembolso" class="reembolso form-control gui-input br-light light" placeholder="">
		</span>
	</div>
</div>
</div>
.....
<script type="text/javascript"
var baseurl2 = "<?php print base_url(); ?>"

$(function () {
					
		 var serv = $(this).parents('.modal').find('.id_reclamacao').val();

		$.ajax({
			url: baseurl2+'reclamacao/get/' + serv,
			type: 'post',
			cache: false,
			dataType: 'json',
			data: serv,
			success: function (data) {
			  var anexo = data['anexo'];
			  console.log(data); // WHAT DOES THIS OUTPUT
			  // Presents the column value
			  $('<p/>').text(anexo).appendTo(document.body);
			},
			error: function(jqXHR) {
				bootbox.alert(jqXHR.responseText);
			}
		});
		
	});
</script>

Open in new window


But it is not functional.

The similar code called when the "Download do Arquivo" button is clicked - at the botton of HTML is functional:
var baseurl = "<?php print base_url(); ?>";

$(".download").click(function(){

	// Usa o id_reclamacao do 1.o modal- Edit que detém o valor
	var serv = $(this).parents('.modal').find('.id_reclamacao').val();

	
	$.ajax({
		url: baseurl+'reclamacao/get/' + serv,
		type: 'post',
		cache: false,
		contentType: false,
		processData: false,
		dataType: 'json',
		data: serv,
		success: function (data) {
		var anexo = data['anexo'];
		//alert(anexo);

	   //  Faz o download
		window.open(anexo);
		
		},
		error: function(jqXHR) {
			bootbox.alert(jqXHR.responseText);
		}
	});
});

Open in new window

0
 
Julian HansenCommented:
Remember this
 $('<p/>').text(anexo).appendTo(document.body);

Open in new window

Will be added at the very end of the document - is that where you want it?
0
 
Eduardo FuerteAuthor Commented:
Yes, it could be a solution.

But it's not presented anywhere, I don't know why.
0
 
Julian HansenCommented:
Are you sure.

Try viewing the HTML in the console - look down where the closing </body> tag is - are you sure it is not there?
0
 
Eduardo FuerteAuthor Commented:
Julian

I opened a paralell question in this subject since the needed value can be obtained in a textbox:

https://www.experts-exchange.com/questions/28976425/Could-you-point-how-to-manipulate-a-textbox-value-before-it's-presented.html

Could you give a look?
0
 
Eduardo FuerteAuthor Commented:
Thanks for help!
0
 
Julian HansenCommented:
You are welcome.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 14
  • 10
Tackle projects and never again get stuck behind a technical roadblock.
Join Now