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
92 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 14
  • 10
25 Comments
 
LVL 58

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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 58

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 58

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 58

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
 
LVL 58

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 58

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 58

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 58

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 58

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 58

Expert Comment

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

Featured Post

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

630 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