Search code examples
jqueryjquery-file-upload

jQuery file upload and save without server side


can you please acknowledge me if there is a way to create a simple file uploader with jQuery and save that file (image) in some folder ... without the use of any server side scripting such as php etc. Here is some simple script i tried so far

 $(document).on("click", "#upload", function() {
    var file_data = $("#avatar").prop("files")[0]; 
    var form_data = new FormData(); 
    form_data.append("file", file_data);
    $.ajax({
                url: "/img",
                dataType: 'script',
                cache: false,
                contentType: false,
                processData: false,
                data: form_data,
                type: 'post'
       });
});

HTML

<form enctype="multipart/form-data" method="post">
    <input id="avatar" type="file" name="avatar" />
    <button id="upload" value="Upload">UPLOAD</button>
</form>

Solution

  • JQuery being JavaScript- no way for it to write to the file system. It needs to use REST API to do writes and other server side operations like interacting with db etc.

    https://github.com/blueimp/jQuery-File-Upload/blob/master/README.md

    Having said that, here is PHP sample/code to process the file.

    https://tutorialzine.com/2013/05/mini-ajax-file-upload-form