Change a form to accept a MS Word type file

Hi,
with some very kind help from this forum I managed to get my little, primitive homework page working. PHP sends me an email with the students’ answers. Works great!

Now, I would like to try and get the form to accept a file as well, which would be an essay written in Word or Open Office. Not a very big file.

Reading a bit on the subject, I’m wondering if I should attach the file to an email or save it on the host.

Which is best?

Will I be able to simply modify my thankyou.php script to handle a file upload, or is that a much more difficult proposition?

I still need the thankyou.php to send me the details of each student, so maybe I can squeeze the file in too?

What I would like to know most of all is how I should go about this.

Then I can file away at some PHP.

I see html has:

`<input type="file" name="fileupload" value="fileupload" id="fileupload">`

Could I just declare another PHP variable? I don't imagine it is that simple!

$fileupload = $_POST['fileupload'];

Thanks in advance for any links, tips or pointers!

Your sentence is missing half of it’s content. Every time you ask what is “best” you need to specify an objective to achieve, so different methods to get there are compareable.

The manual has a good tutorial about file uploads:

https://www.php.net/manual/en/features.file-upload.post-method.php

Well, actually, and best for me is send the file directly with the email to myself. The reason is, I will download with Python and save to my laptop. I will get a lot of emails

I am looking here: and here

However, the latter link wants me to install something called pear

The pear classes PEAR::Mail and PEAR::Mail_Mime are used for sending the email with the attachment.

I don’t know if I can install things like that on my web host.

Does this seem like the way to do this to you experts?? Is it at all possible to send and attachment with PHP mail() ???

Yes it is, but i wouldn’t recommend doing this on your own, because it’s a bit complicated for a beginner to implement all neccessary requirements. And there are several wrappers that make it really easy to send mails with attachment while they already care for certain security risks. Have a look at PHPMailer and SwiftMailer.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service