Uploading image file from Webdialog to php-script?
-
Hi!
I´m trying to send a jpeg file from the webdialog to a php-script to save it server-side. The background is, that I want to create a little preview of the Sketchup model with the write_image function which shall be used for further purposes. I already found out, that I can´t upload a file with javascript for security reasons, so I use a form within the Webdialog. Inside this form there is a filechosser and an invisible iframe. The invisible iframe will recieve the php answer, so that the webdialog won´t reload or some other unwanted behaviour will occur.
Now my problem is, when clicking the submit button the php-script ist not beeing called, nor is the onsubmit event beeing triggered and it looks like the ruby script creating the webdialog reloads. I searched this forum for solutions and found that probably it´s not possbile to submit forms with an
<input type="submit"/>
element.
Of course I could use a normal button instead and bind a function to it, but how will I get the chosen image-file within the form to be uploaded to the php-script?
Any ideas?
This is my html code so far:
<form id="frm_icon_upload" action="icon_upload.php" method="post" enctype="mulitpart/form-data" onsubmit="debugAlert()"> <input type="submit" name="action" value="Upload"/> <input type="file" name="icon" id="icon"/> <iframe id="upload_target" name="puload_target" src="" style"..."></iframe> </form>
-
If you sit a url in a webdialog you can use something like http://www.tizag.com/htmlT/htmlupload.php
-
Never use the method, but:
WebDialog.post_url
https://developers.google.com/sketchup/docs/ourdoc/webdialog#post_url -
Thanks for your advices. I have tested the post_url method before, but I guess you can only submit the values of <input> elements like text areas or buttons in the url, no images. I decided to drop that feature for now, may I will implement it later. There seem´s to be another approach using the flash file upload abbility, may be I´ll give it a try then.
-
You could BASE64 encode the image...
-
I didn´t know about that possibility and it really seems to be just what I´m looking for. I will definitely give it try.
Thanks!
Advertisement