How to store uploaded file into server path using either javascript or jquery

末鹿安然 提交于 2019-12-12 03:22:39

问题


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.


回答1:


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
});

});



来源:https://stackoverflow.com/questions/32842207/how-to-store-uploaded-file-into-server-path-using-either-javascript-or-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!