PHP Keep the User's File Upload Path After Validation Fail

自古美人都是妖i 提交于 2019-12-08 04:32:32

问题


i want to ask that if its possible to keep the user's upload path where he selects from his computer that which file will be uploaded like the path " C:\Users\User1\Desktop\1.jpg " , the reason i want to learn about this is after submitting forms with php when he fails about validation, i want him to not reselect it..

Summary : How can i save the path : C:\Users\User1\Desktop\1.jpg in user's form if user fails on other field's validation

Thanks


回答1:


It is not possible. Only the filename is sent by the browser, not the full path.




回答2:


First thoughts

I am just posting this in case you think of doing something crazy like, why don't I use javascript or JS library to get the path?

It's a DOM element after all.

Well browsers are your enemy!! why? For security reasons, browsers have security restructions like as you have guessed don't expose the local file structure.

Question What would you do with the file path? How's a file path going to be handy on the server-side?

Hem, let me think...still thinking.....

The only purpose that I can think of is discovery before attempting a hacking.

Field validation can be an honest answer, but you can avoid this by creating a form that uses AJAX to submit the data to sever.

What??

Yes sir, use ajax submit the data as post, validate it and send a message back to the browser stating if the form was successfully submitted or not.

With ajax you don't leave the page when data is submitted to the server



来源:https://stackoverflow.com/questions/12159218/php-keep-the-users-file-upload-path-after-validation-fail

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