I have two input fields, one with a type = file and other
type The form is =
/ li>
File name of the uploaded file
Upload to dir / file_name in the Type = text field the file was uploaded correctly The problem is that I get the file name incorrect, depending on the browser I'm using.
- Firefox works fine and I get:
somepath / file_name.ext
IE (10) I get the full local file path: some path / c: \ user \ user \ desktop \ file_name.ext
Chrome < / Strong> All are cute and return: sompt / C: \ fakepath \ file_name.ext How do I solve it? I need only to file_name.ext , such as Firefox does not have to say that the file name should be detected and the appropriate text field to be replaced Because the file is selected and before the form is submitted.
HTML Part:
& lt; Form enctype = "multipart / form-data" action = "" method = "post" & gt; & Lt; Input name = "data_up" id = "data_up" type = "file" /> gt; & Lt; Br> & Lt; Input name = "data" id = "data" type = "text" value = " PHP part (requires simplified, security):
if (isset ($ _ POST ['submit']) {if ($ _FILES ["Data_up"] ["Error"] == 0] {move_uploaded_file ($ _ files ["data_up"] ["tmp_name"], "some path /" [files] ["data_up"] ["name"] ); }} JS Part:
& lt; Script type = "text / javascript" & gt; $ (Function () {$ ('# data_up'). Change (function () {var fileName = $ (this) .val (); $ ('# data'). Val ('somepath /' + fileName); });}); & Lt; / Script & gt;
Just remove the last string before the last slash. What is the same in your case back Has come and X is what you want
var v = 'some \\ thing \\ text.txt'; Var x = ''; For (i = v.length-1; i> = 0; i--) if (v [i]! = '/' & Amp; amp; amp; amp; ve [i]! = '\\') x = V [i] + x; And break; Console.log (x);
Solution 2:
var v = 'some / cheese / text.txt' ; Var y = v.split (/ [\\\ /] /); Var x = y [y.length-1]; Console.log (x);
Solution 3:
var v = 'vava \\ text.txt'; Console.log (v.replace (/.*[\\\/]/g, ''));
No comments:
Post a Comment