Link to home
Start Free TrialLog in
Avatar of Eduardo Fuerte
Eduardo FuerteFlag for Brazil

asked on

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
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

I think the image you posted relates to your other question.

Can you show us the HTML for the table.
Avatar of Eduardo Fuerte

ASKER

Hi

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

The relevant part I'm trying to implement starts at  line 560
codigo_tela_131016.php
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 ?
Julian


The relevant picture was eliminated  with the other ...

User generated image
The above jQuery I posted must retrive the database column "anexo"  value and simply present it  when the view is presented.
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?
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.
Our messages crossed... just a moment.
The html anexo that you saw refers to upload feature:


User generated image
  <!-- 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...
Yes I understand but I don't know what the HTML for the anexo file is displayed.
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)
And it just displays the db table's column content obtained in jQuery.
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.
Isn't it possible to print directly in the document body ?
like:

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

Open in new window

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.
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:
User generated image
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?
ASKER CERTIFIED SOLUTION
Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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:
User generated image
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

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?
Yes, it could be a solution.

But it's not presented anywhere, I don't know why.
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?
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?
Thanks for help!
You are welcome.