-1

I was hoping someone could help me/guide me in the right direction with this issue.

I want to create a button called "Send File". When this button is clicked, a directory on my web server is opened where multiple PDF files are stored. I must then have the option of selecting multiple files. Once I click "Okay/Confirm", a new mail must be opened on Outlook with the files added as attachments.

So it's basically like adding an attachment on your local computer through Outlook, but the only difference is the "source" of the file is in a directory on my web server.

I hope this question isn't too broad or not specific enough. I have really no idea how to go about this, so any tips are appreciated. I will attempt to write some code but I don't have a clue on how I'd do this.

MailBlade
  • 339
  • 4
  • 19
  • 1
    I would create a select box or multiple checkboxes with the names of the files in that directory. Let the user pick which file(s) and then add those as an attachment to an email that your server sends to the user. Use a email class like PHPMailer to send your emails. It will save you many headaches when it comes time to attach the files to the email. – Joseph_J Jun 12 '18 at 06:53
  • I was thinking of creating checkboxes, but would I have to create a checkbox for each of the files located in the directory? So basically the checkbox or select box "values" would be the file names? Do you know how to assign the "name" of the checkbox to the file name? Thank you so much for your answer! – MailBlade Jun 12 '18 at 07:51
  • 1
    You create an array with the file names from your directory. Then you loop over the array to make the checkboxes. Plenty of material to search on SO about creating checkboxes by looping over an array. Build a basic example to test. – Joseph_J Jun 12 '18 at 07:56
  • Luckily I know how to do both of those things! I'm still quite new and have a lot to learn, so thank you so much for helping me out! I'll have a search on SO (it's helped me a lot in the past) – MailBlade Jun 12 '18 at 08:03

2 Answers2

0

Here is a quick example:

print_r($_POST['fileName']);

$array = array(

  'file1.pdf',
  'file2.pdf',
  'file3.pdf',
  'file4.pdf',
  'file5.pdf',
  'file6.pdf',
  'file7.pdf',
  'file8.pdf',

);

echo '<form action="" method="post">';

foreach($array as $file){

   echo $file . '<input name="fileName[]" type="checkbox" value="' . $file . '"><br>';

}

echo '<input name="submit" type="submit" value="Submit">';

echo '</form>';
Joseph_J
  • 3,654
  • 2
  • 13
  • 22
  • Thank you so much! I really appreciate it. Gives me a good base to work form :) – MailBlade Jun 12 '18 at 11:11
  • Hi @Joseph_J. Just one question: How would I go about making $array into the full directory, listing all the files in the directory automatically? I'd be very grateful if you could assist me with it. Thank you. – MailBlade Jun 12 '18 at 11:50
0

This isn't possible.

There is no way for the browser to tell the user's email client (Outlook or otherwise) to start a new email with specific attachments (no matter what the source of the attachments).

Instead, you could send the email directly from the server.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks for your reply. So PHP Mailer would basically be the easiest way to do this. The thing is though, how can I tell PHP Mailer that it should find the file where the checkbox is clicked, and send that in an email? – MailBlade Jun 12 '18 at 09:26