Reputation:
I have a file field in my form.
I want the user to be able to choose an image, press OK, and then without submitting the form, preview the image in a smaller resized way. If everything is to the satisfactory of the user, then hit submit and the image as well as the form is submitted...
How would you good professionals do this basically?
Thanks
Upvotes: 2
Views: 6212
Reputation: 1188
You can use the tag for this.
Basically, you put your upload field to an iframe. When a user uploads an image, the iframe gets reloaded, but not the whole page, at the mean time on the server side you peform resizing.
Upvotes: 0
Reputation: 20397
When you've uploaded the image once, there's no point uploading it a second time, you may as well keep the copy already on the server, so long as you have some way to tie it back to the form once that's submitted, or removing it if the form is never submitted.
Cleaning up uploaded images is a problem you will have to solve anyway. Once you've uploaded the image, the server will have to keep it around, as the browser will have to request the image in a second request to be able to display it.
I would do this then:
Cleaning up uploaded images that you don't want (say the user adds a couple of pictures, and then closes the browser without submitting the main form), is a separate issue, and how you deal with it will depend on what sort of application you are developing.
Upvotes: 0
Reputation: 7406
I think the best method would be:
Here's an article which also might help you out
Upvotes: 0
Reputation: 30985
You might want to have a look to the following:
http://www.atwebresults.com/php_ajax_image_upload/
Upvotes: 0
Reputation: 140195
You need to submit at least a form to upload the file and display it. You can simulate an Ajax upload by using an iframe.
Upvotes: 5