Programmatically set name of file to upload in webpage

我只是一个虾纸丫 提交于 2020-01-21 09:47:28

问题


Is there a way to programmatically set the name of a file to be uploaded from a web page? I suspect that browser security restrictions make this impossible, but I'm hoping someone will prove me wrong.

I have a web application that needs to let the administrator upload HTML. The admin selects the HTML file, then the app uploads that file, plus figures out all the supporting files (images, stylesheet, etc) and uploads them too. There doesn't seem to be a way to programmatically upload the supporting files from a web page, since the user has to specify each file explicitly.

Currently I have a separate Windows app to do this, but it would be ideal to have this functionality integrated with the rest of the app. My back end is ASP.NET with C#.


回答1:


There is no way to programatically grab files from a user's computer via the browser. This would be a security violation if a website could just grab things.




回答2:


No, you cannot do this without a client-side application or special plug-in.

Browser security doesn't allow the server to obtain information about the hard drive contents of the client.




回答3:


You may be able to do this using some form of browser plug-in. This is more work for you (and there are potential security implications for this beyond those found when you just have users run your app). However, it may prevent a more integrated experience for your users. I'd hesitate to eliminate the application completely, though. Browser compatibility issues are common.




回答4:


Yes you can (in modern browsers)...

You can get and set the value of HTMLInputElement.files. See this answer.



来源:https://stackoverflow.com/questions/997977/programmatically-set-name-of-file-to-upload-in-webpage

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