Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just for fun I thought I'd knock it up. It ended up being trickier than I thought because I went in not fully understanding how the boundary part works, eventually I worked out that the starting and ending '--' were significant and off it went.</p> <pre><code>&lt;?php if(isset($_POST['submit'])) { //The form has been submitted, prep a nice thank you message $output = '&lt;h1&gt;Thanks for your file and message!&lt;/h1&gt;'; //Set the form flag to no display (cheap way!) $flags = 'style="display:none;"'; //Deal with the email $to = 'me@example.com'; $subject = 'a file for you'; $message = strip_tags($_POST['message']); $attachment = chunk_split(base64_encode(file_get_contents($_FILES['file']['tmp_name']))); $filename = $_FILES['file']['name']; $boundary =md5(date('r', time())); $headers = "From: webmaster@example.com\r\nReply-To: webmaster@example.com"; $headers .= "\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"_1_$boundary\""; $message="This is a multi-part message in MIME format. --_1_$boundary Content-Type: multipart/alternative; boundary=\"_2_$boundary\" --_2_$boundary Content-Type: text/plain; charset=\"iso-8859-1\" Content-Transfer-Encoding: 7bit $message --_2_$boundary-- --_1_$boundary Content-Type: application/octet-stream; name=\"$filename\" Content-Transfer-Encoding: base64 Content-Disposition: attachment $attachment --_1_$boundary--"; mail($to, $subject, $message, $headers); } ?&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt; &lt;title&gt;MailFile&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;?php echo $output; ?&gt; &lt;form enctype="multipart/form-data" action="&lt;?php echo $_SERVER['PHP_SELF'];?&gt;" method="post" &lt;?php echo $flags;?&gt;&gt; &lt;p&gt;&lt;label for="message"&gt;Message&lt;/label&gt; &lt;textarea name="message" id="message" cols="20" rows="8"&gt;&lt;/textarea&gt;&lt;/p&gt; &lt;p&gt;&lt;label for="file"&gt;File&lt;/label&gt; &lt;input type="file" name="file" id="file"&gt;&lt;/p&gt; &lt;p&gt;&lt;input type="submit" name="submit" id="submit" value="send"&gt;&lt;/p&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>Very barebones really, and obviously the using inline CSS to hide the form is a bit cheap and you'd almost certainly want a bit more feedback to the user! Also, I'd probably spend a bit more time working out what the actual Content-Type for the file is, rather than cheating and using application/octet-stream but that part is quite as interesting.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload