简体   繁体   中英

Send image path via AJAX

so I have this form where I add item to my DB. Fiedls are:

Name, Description, Image.

Problem is with image, I want to send the new values via AJAX using jQuery to my submit file. Reason for this is to not refresh any page. Everything is fine except IMAGE because browsers keep making the path private ex. "C:\\fakepath\\myImg.png".

Is it possible to somehow send my image path, because it works with default <form method="post...></form> , only problem is that it is refreshing the page, that's why I want to use AJAX.

Sorry, my native language is not English so maybe you didn't understand me clearly :)

I'm after full path to UPLOAD the image in my submit file. I can't upload image without knowing it's full path, can i?

You can use jquery.form plugin to upload forms without reloading the page.

Examples: http://www.malsup.com/jquery/form/#code-samples

The browser keeps making it a "private" path because the browser client has no knowledge of your server structure and it only knows the path where it is stored on the client machine. The upload goes to a temporary location on your server and it is up to you on the server side to move it from the temporary path to the place you want to store the file,

So in that sense, no you can't specify the destination path using AJAX.

In addition, you never want to allow the client to specify a location on your server. Even allowing them to specify the name that the file will be stored as is a potential security risk.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM