Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="preview"><img src="img/logo.png" class="original"></div>
- <div id="button1">Upload</div><span id="status"></span>
- <ul id="files"></ul>
- <script src="js/ajaxupload.js" type="text/javascript"></script>
- <script src="js/jquery.myimgscale-0.2.min.js" type="text/javascript"></script>
- <script src="js/jquery.myimgscale-0.2.js" type="text/javascript"></script>
- <script>
- var button = $('#button1');
- var status = $('#status');
- new AjaxUpload(button, {
- action: 'upload-handler.php',
- name: 'userfile',
- onSubmit : function(file, ext){
- if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
- // check for valid file extension
- status.text('Only JPG, PNG or GIF files are allowed');
- return false;
- }
- // change button text, when user selects file
- button.text('Uploading');
- // If you want to allow uploading only 1 file at time,
- // you can disable upload button
- this.disable();
- },
- onComplete: function(file, response){
- button.text('Done');
- // enable upload button
- this.disable();
- //On completion clear the status
- status.text('');
- //Add uploaded file to list
- if(response==="success"){
- $('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'" alt="" class="newImg" /><br />'+file).addClass('success');
- } else{
- $('<li></li>').appendTo('#files').text(file).addClass('error');
- }
- $('img.original').replaceWith( $('img.newImg'));
- $('img.newImg').scaleImage({scale: 'fit'});
- }
- });
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement