Solved

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

Posted on 2016-10-11
25
68 Views
Last Modified: 2016-10-26
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
Comment
Question by:Eduardo Fuerte
  • 14
  • 10
25 Comments
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41839586
I think the image you posted relates to your other question.

Can you show us the HTML for the table.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41841789
Hi

Please desconsider image img_EE_111016_005.png - I forgot to delete it. The relevant imageto this question is appearing.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41842039
Here is the code:

The relevant part I'm trying to implement starts at  line 560
codigo_tela_131016.php
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41842120
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
 

Author Comment

by:Eduardo Fuerte
ID: 41842196
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
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41842206
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
 

Author Comment

by:Eduardo Fuerte
ID: 41842209
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
 

Author Comment

by:Eduardo Fuerte
ID: 41842213
Our messages crossed... just a moment.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41842227
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
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41842529
Yes I understand but I don't know what the HTML for the anexo file is displayed.
0
 

Author Comment

by:Eduardo Fuerte
ID: 41842541
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
 

Author Comment

by:Eduardo Fuerte
ID: 41842552
And it just displays the db table's column content obtained in jQuery.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41842557
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
 

Author Comment

by:Eduardo Fuerte
ID: 41842567
Isn't it possible to print directly in the document body ?
like:

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

Open in new window

0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41842573
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
 

Author Comment

by:Eduardo Fuerte
ID: 41842627
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
 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41842693
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
 

Author Comment

by:Eduardo Fuerte
ID: 41842764
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
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41843120
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
 

Author Comment

by:Eduardo Fuerte
ID: 41843456
Yes, it could be a solution.

But it's not presented anywhere, I don't know why.
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41843486
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
 

Author Comment

by:Eduardo Fuerte
ID: 41843554
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
 

Author Closing Comment

by:Eduardo Fuerte
ID: 41860096
Thanks for help!
0
 
LVL 51

Expert Comment

by:Julian Hansen
ID: 41860148
You are welcome.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
echo button 13 45
Asp.net mvc 5 5 16
Getting info from database not working 6 11
Strip leading 0 from a var 3 11
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now