Hi I want to create a newsletter module from where i can send newsletters to multiple emails. The images will be embedded in the email.
Now, let me describe the problem: The body for the email(html code) is pasted into the text area. Now, to embed the image, i need to upload the image to the server. How do i upload the image, probably after extracting the src from the image tag? Is it possible since the field is not of file type? If my approach is not correct what is a possible approach?
You could parse the HTML that is uploaded either manually or using an XML validator (although good luck handling poorly formatted HTML). Its a good idea especially if you want to make sure people don't upload malicious code, as an example, such parsers usually remove all but the most basic HTML tags like bold/italic/etc. One its parsed, finding the img tag is then trivial.
Another method is just to convert the entire html file into a single string and try using regular expressions to match an image tag.
Really for uploading files though, I recommend a form upload button to explicitly upload the files. There's no telling how many files or how big they will be if you start uploading from external sites. [ August 16, 2006: Message edited by: Scott Selikoff ]
MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
Joined: Jul 17, 2006
Thanks for the replies. Actually I can extract the file details from the html. That is not the problem now. My problems are after i extract the file details, what do i do next? ie how do i upload the files given in the html? If it is not possible, please suggest a workaround. As i said the field is just textarea and not file field. I have never done this before so any help is welcome. [ August 16, 2006: Message edited by: azhar bharat ]
Even if you know the location of an image file on the client machine, you're not going to be able to get the browser to upload it to you without the user explicitly clicking on a 'file' input button, selecting the image and submitting your form. Browser makers take great care to insure that this is the only way an upload is performed.