Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8634563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:45:23+00:00 2026-06-12T09:45:23+00:00

I am trying to rename a file from a modal window. The modal window

  • 0

I am trying to rename a file from a modal window. The modal window runs fine and so does the php code for renaming the file. I have tried many different ways to send the data whithout exiting.

The form gets the value of a link image: name, directory and diferent actions: delete, update and resize. So when I click the link it opens the modal window with these values (I have also noticed that the value is the same when I click other image links each time)
The problem is that is not sending any value. I supose that there is a problem getting values: for example val() is a jQuery method. .value is the DOM Element’s property, I would like to know how can I solve this.

the html code:

   <div id="dialogo" title="Editar Imagen">
<p class="validateTips">Campo titulo requerido.</p>
    <!--action="" method="post"-->
<form id="update" >
<fieldset>
    <label for="titulo">Titulo</label>
    <input type="text" name="titulo" id="titulo" class="text ui-widget-content ui-corner-all" />
    <label for="Alt">Alt</label>
    <input type="text" name="Alt" id="Alt"  class="text ui-widget-content ui-corner-all" />
    <label for="descripcion">Descripcion</label>
    <input type="text" name="descripcion" id="descripcion"  class="text ui-widget-content ui-corner-all" />
</fieldset>
</form>
   </div>

the ajax/jquery code:

    <script type="text/javascript">
     $(document).ready(function(){
     var fname=$('a.ico-resize').attr("id");
     var directory=$('a.ico-resize').attr("rel");
     var deletecount=$('a.ico-resize').attr("value");
     $('#titulo').val(fname);
     $('#Alt').val(directory);
     var descripcion = $("input#descripcion").val();
     var dataString = 'descripcion='+ descripcion + '&titulo=' + titulo + '&Alt=' + Alt;
     // var data_string = $("#update").serialize();


// Damos formato a la Ventana de Diálogo
var dialog = $("#dialogo").dialog({
    // Indica si la ventana se abre de forma automática
    autoOpen: false,
    // Indica si la ventana es modal
    modal: true,
    // Largo
    //width: 400,
    // Alto
    //height: 280,
    // Creamos los botones      
    height: 300,
    width: 350,
    buttons: {
        
        'Rename Image': function() {
            // Mostrar Versión de PHP
            $.ajax({
                // Antes de realizar la llamada mostramos el ajax load
                beforeSend: function(){
                    $('#respuestaAjax').html('<img id="loader" src="images/loading.gif"/>');
                },
                //cache: false, // Indicamos que no se guarde en cache
                type: 'post', // Variables GET
                url:'rename_img.php', // srcript a ejecutar
                 data: dataString,
                 
                 //'titulo=titulo&descripcion=descripcion&Alt=Alt',
                 
                 //$("form#update").serialize(),

                 //{"file":fname,"directory":directory, "descripcion":descripcion},  // paso de datos
                // cuando es exitoso el llamado
                    success: function(response){
                     $('#respuestaAjax').html(response);
                    $('#' + deletecount).remove();
                        dialog.dialog( "close" );
                }
            });
        },
        Cerrar: function() {
            // Cerrar ventana de diálogo
            dialog.dialog( "close" );
        }
    }
});

     $("a.ico-resize").click( function(e) {
         e.preventDefault();
         // dialog.dialog("open");
           dialog.dialog('open');
    // prevent the default action, e.g., following a link
    return false;
          });
          });
                   
        </script>

php code:

    <?php 

     $dir = $_POST['Alt'];
     $file = $_POST['titulo'];
      $nuevo= $_POST['descripcion'];
     $img  = $dir."/".$file;
     $imagen =  $dir."/".$nuevo;

     //unlink ($img);
      rename($img, $imagen);
      echo $imagen;
      ?>

solved

finally all works with this code:

          <script type="text/javascript">
        
         $(function(){
          var fname=$('a.ico-resize').attr("id");
          var directory=$('a.ico-resize').attr("rel");
          var deletecount=$('a.ico-resize').attr("value");
          $('#titulo').val(fname);
          $('#Alt').val(directory);
          var descripcion = $('#descripcion').val(); 
          var data_string = $("#update").serialize();
          var dialog = $("#dialogo").dialog({
    
        autoOpen: false,    
        modal: true,    
        height: 300,
        width: 350,
        buttons: {
        
            Send: function(){
            
            str = $("#update").serialize();
                
                $.ajax({
                    
                    beforeSend: function(){
                        $('#respuestaAjax').html('<img id="loader" src="images/loading.gif"/>');
                    },
                    cache: false, 
                    type: 'POST', 
                    url:'rename_img.php', 
                    data: str,
                    contentType: "application/x-www-form-urlencoded", 
                    success: function(response){
                        
                         $('#respuestaAjax').html(response);
                         $('#' + deletecount).remove();
                         dialog.dialog( "close" );
                    }
                });
                },
                Cerrar: function() {
                    dialog.dialog( "close" );
                }
            }
        });

            $("a.ico-resize").click( function(e) {
        
              var id = $(this).attr('data-id');
              var rel = $(this).attr('data-rel');
              var value = $(this).attr('data-value');
             $("#update").find("#titulo").val(id);
             $("#update").find("#Alt").val(rel);
            
            dialog.dialog('open');
        });
        });
                   
        </script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T09:45:24+00:00Added an answer on June 12, 2026 at 9:45 am

    The code looks fine as far as sending itself is considered. I mean it probably does send the request it’s just the query that is wrong. (You can check in the firebug’s console if the request is really send or not).

    What you need to change is the place where you build the dataString. You build it once the page is loaded (in the $(document).ready function) so it’s never rebuild after you change the values in your modal window.

    You should move the code responsible for building dataString to the click handler of a.ico-resize.

    Also I can’t see where the titulo and Alt variables are set and, as you can see in your Firebug, they’re set wrong.

    Try this:

    var dataString = 'descripcion='+ $('#descripcion').val() + '&titulo=' + $('#titulo').val() + '&Alt=' + $('#Alt').val();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying to execute the xxx.bat file for rename the file from my
I have been trying to work out a file rename program based on ruby,
I'm trying to rename the uploaded file with the rename-addFilter. The actual upload already
trying to rename all files in a directory to $arg[1] + number of file
I am trying to rename many files in my application and need to be
I'm trying to redirect my clients from: /media/pdf/pds/.../file.pdf -> /media/pdf/pds/English/.../file.pdf My current approach, witch
I am trying to move a file from one directory to another using renameTo()
I am trying to rename an image in Gallery taken from Camera to give
I'm trying to get data from CSV file , by using fill() method i
I am trying to do a really basic rename of a file to another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.