UploaderPreviewer jQuery Plugin

The UploaderPreviewer jQuery Plugin allows to preview an image that has been selected in a form.

The image is sent to the server and resized when it is selected. Then it is displayed.

The images are not stored till the "Save" button is pressed. Till then they are kept in a temporary directory and deleted if the user exits or reloads the page.

The images may be stored with a descriptive name. For it, three random keywords are taken from a given keyword list that may come from the product name, tags, address, etc. This feature is useful for SEO.


Demo

Field to show the integration of the image plugin with other fields.
Field to test the descriptive image names from a keyword list. Separate the keywords by ','.

Download

Last version: 2.3

Download this demo with last version of uploaderPreviewer


Documentation

Working Description

When a file field is changed, the selected file is uploaded to a temporary directory with a temporary filename. It is resized to medium and thumb sizes, and the thumb image is previewed.

When the user clicks the "Save" button, the files in the temporary directory are moved to the uploads directory.

A list of keywords can be indicated to construct the final filename. This keywords may come from the product name, tags, address, etc. This feature is useful for SEO purposes.

If there is an error in the upload process, it is displayed above the corresponding file field.

If the user doesn't save the form and exits or reloads the page the files in the temporary directory are deleted, in order not keep unnecessary files.

Initialize forms to insert files

Write in the page an imageForms class div:

<div class="imageForms"></div>

It must be initialized in the $(document).ready() jQuery function:

$('div.imageForms').append($.uploaderPreviewer.createImageForms());

The number of image forms that will be created is defined by the property formsCount, in uploaderPreviewer.js. It may be overwritten in the optional options parameter of createImageForms().

Initialize forms to update files

Write in the page an imageForms class div with an images attribute, containing the filenames of the uploaded files:

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

It must be initialized in the $(document).ready() jQuery function:

if ($('div.imageForms[images]').length) {
var imageFilenames = $('div.imageForms[images]').attr('images').split(',');
$.uploaderPreviewer.populateImages(imageFilenames);
$('div.imageForms[images]').removeAttr('images');
}

Configuration

The /uploads directory and its subdirectories must have write permission.

The configuration of the server side is all done in the configuration.php file.

The configuration of the client side is done at the top of following javascript files: uploaderPreviewer.js and itemForm.js.

uploaderPreviewer.js:

itemForm.js:

Files Included

These are the main files of the plugin. They manage the dynamic uploading, resizing and previewing of the images.

Manage the saving and uploading of the uploaded files from the temporary directory to the final one.

Includes the configuration parameters, like upload paths, maximum image size, etc.

Includes utility functions, like displaying dialog box, display errors, etc.

Manage the ajax requests to insert and upload files. The upload file has no functionality in this demo, as it requires the database stored images filenames, in order to compare them with the new ones and see if they have been changed.

jQuery and jQuery UI libraries. The jQuery UI library is only used to display dialog boxes and a progress bar.

Key functions to customize

Features

Known flaws

Comments

If you want to leave any comment, please post it here

http://www.webdeveloper.com/forum/showthread.php?t=209720

Si quieres dejar algún comentario en español, por favor, hazlo aquí

http://www.forosdelweb.com/f127/subir-reducir-vista-previa-imagen-con-ajax-ejemplo-completo-702709/