Ver Mensaje Individual
  #29 (permalink)  
Antiguo 22/07/2012, 16:02
negromelchor
 
Fecha de Ingreso: septiembre-2011
Mensajes: 17
Antigüedad: 13 años, 3 meses
Puntos: 0
Respuesta: Subir, reducir y vista previa de una imagen con AJAX - Ejemplo completo

Hola AMS, encontré en un foro en Inglés una respuesta en la que explicas como editar/actualizar las imagenes ya subidas:

Check the Initialize forms to update files section in the documentation (http://dondedeportes.es/uploader-previewer). There you can see:

Code:

<div class="imageForms" images="image1.png,image2.jpg,image3.gif"></div>

You have to place the existing image names in the imageForms div, within the images attribute.

You have to read this attribute in javascript and populate the image forms, in the $(document).ready(), for instance. The attribute may be removed in order to clean the code:

Code:

if ($('div.imageForms[images]').length) {

var imageFilenames = $('div.imageForms[images]').attr('images').split(',');

$.uploaderPreviewer.populateImages(imageFilenames) ;

$('div.imageForms[images]').removeAttr('images');
}

The image names in the comma-separated string are splitted into an array, which is used by populateImages().

So far, if the plugin configuration is right, the images should be displayed on page load. And also if the configuration is right, you will be able to remove or replace anyone of them.

The working flow in the form is the same for insert and for update. The difference comes when the form is submitted. For an update, you will have to loop over every image and call the complex function updateUpload() of uploadedFile.php.

updateUpload() gets the name of the image comming from the form, the name of the stored image and a keyword list. If both names are equal, this means that the image remains as it was. Nothing is performed. The stored image name (which is equal to the image name from the form) is returned.

If the names are different, this means that the image was changed. Then, the old image is deleted and the new one moved from the temp directory, were it was, to the uploads directory. A new filename is generated with the keyword list. The new filename is then returned.

Me podrias dar un ejemplo del punto marcado en negrita? Es que no logro actualizar las imagenes, updateUpload no me devuelve nada.

Muchas gracias!!!