0

I want to know that how can I store my uploaded file from my local system into one server path like('/newfolder/tests/') using either javascript or jquery, Please provide me any solution for it as I'm new to this Files system.

html:

  <input type="file" id="inputfile" name="inputfile"></input>

js:

  var path =$('input[type=file]').val().replace(/C:\\fakepath\\/i, '');

is giving my uploaded file names only`, so that I need to store/save this variable on any server path(or any File system path),and I'm not using any database here, so that I can grab it from that path and can display it on my view page.

Muhammad Usman
  • 1,366
  • 5
  • 18
  • 33
Dhana
  • 711
  • 3
  • 14
  • 40
  • you want to upload file ??? – Muhammad Usman Sep 29 '15 at 11:03
  • Hi Thanks for your replay Usman, I want to store my uploaded file at specific location of server(or at any File System), so that I can grab it from there and can display on my page. – Dhana Sep 29 '15 at 11:11
  • 1
    could you be more specific? which server language are you using? javascript is a client side language, it isn't able to save your uploaded file, your server code must know where the uploaded file was saved and return this information. – Ricardo Pontual Sep 29 '15 at 11:11
  • 1
    provide what have you tried already and I am with @Ricardo Pontual: – Muhammad Usman Sep 29 '15 at 11:13
  • i would like to store it in Filesystem path. Otherwise Can I store it on browser and can we get it from browser ? I'm not using any database here btw. – Dhana Sep 29 '15 at 11:14
  • @Dhana as I wrote, to upload a file you need some server code, so I suggest you google it for how to upload a file your file using your language, php, .net, java.... when you save a uploaded file you know where it will be saved, so the path is easy to discover – Ricardo Pontual Sep 29 '15 at 11:24
  • I've edited my question, please check once and let me know for anything. – Dhana Sep 29 '15 at 11:25
  • JS run on client machine and can't allow you to write to the server unless you are using an action running on the server that will write to the location of your choice. You will be using some file systems code that allows you to have access to a given disk(normally where your code is running) – Jack M Sep 29 '15 at 12:16
  • Can we implement this with Localstorage of html5? if yes, please let me know how can I do ? – Dhana Sep 30 '15 at 04:48

1 Answers1

0

Try This

$('#imageInput').change(function(){
var frm = new FormData();
frm.append('imageInput', input.files[0]);
$.ajax({
    method: 'POST',
    address: 'url/to/save/image',
    data: frm,
    contentType: false,
    processData: false,
    cache: false
});

});

Jay Momaya
  • 1,831
  • 19
  • 32