0

I'm looking for a JQuery or ajax file uploader without flash. I'm not that much aware of html, ajax and JQuery. So please help me. I want code that will do my functionality.

JMax
  • 26,109
  • 12
  • 69
  • 88
Prasad007
  • 103
  • 3
  • 7

2 Answers2

0

I use valums/file-uploader and I am pretty happy with it.
It's very easy to use.
You can find some of my answers about this tool here and here.

HTML:

<div id="uploaderFile"></div>

Javascript:

function CreateImageUploader() {
    var uploader = new qq.FileUploader({
        element: $('#uploaderFile')[0],
        template: '<div class="qq-uploader">' +
                              '<div class="qq-upload-drop-area"><span>Drop files here to upload</span></div>' +
                              '<div class="qq-upload-button ui-button ui-widget ui-corner-all ui-button-text-only ui-state-default">Seleziona il Listino Excel</div>' +
                              '<ul class="qq-upload-list"></ul>' +
                              '</div>',
        hoverClass: 'ui-state-hover',
        focusClass: 'ui-state-focus',
        action: 'Home/UploadImage',
        allowedExtensions: ['jpg', 'gif'],
        params: { },
        onSubmit: function(file, ext) {

            },
        onComplete: function(id, fileName, responseJSON) {
            $("#PopupImageUploader").dialog('close');
            }
        }
    });
}
Community
  • 1
  • 1
LeftyX
  • 35,328
  • 21
  • 132
  • 193
0

@Prasad 007 Replace the below piece of code in doajaxfileupload.php and before that create folder "upload" inside folder "AjaxFileUploaderV2.1"

<?php
    $error = "";
    $msg = "";
    $fileElementName = 'fileToUpload';
    if(!empty($_FILES[$fileElementName]['error']))
    {
        switch($_FILES[$fileElementName]['error'])
        {

            case '1':
                $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
                break;
            case '2':
                $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form';
                break;
            case '3':
                $error = 'The uploaded file was only partially uploaded';
                break;
            case '4':
                $error = 'No file was uploaded.';
                break;

            case '6':
                $error = 'Missing a temporary folder';
                break;
            case '7':
                $error = 'Failed to write file to disk';
                break;
            case '8':
                $error = 'File upload stopped by extension';
                break;
            case '999':
            default:
                $error = 'No error code avaiable';
        }
    }elseif(empty($_FILES['fileToUpload']['tmp_name']) || $_FILES['fileToUpload']['tmp_name'] == 'none')
    {
        $error = 'No file was uploaded..';
    }else 
    {
                        if (file_exists("upload/" . $_FILES["fileToUpload"]["name"]))
      {
      $msg .= $_FILES["fileToUpload"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
      "upload/" . $_FILES["fileToUpload"]["name"]);
      $msg .= "Stored in: " . "upload/" . $_FILES["file"]["name"];
      $msg .= " File Name: " . $_FILES['fileToUpload']['name'] . ", ";
            $msg .= " File Size: " . @filesize($_FILES['fileToUpload']['tmp_name']);
      }

            //for security reason, we force to remove all uploaded file
            //@unlink($_FILES['fileToUpload']);
    }       
    echo "{";
    echo                "error: '" . $error . "',\n";
    echo                "msg: '" . $msg . "'\n";
    echo "}";

?>
mymotherland
  • 7,968
  • 14
  • 65
  • 122