PHP发送文件而不带扩展名到电子邮件


php sending file without extension to email

我有一个页面,用户将他们的文件上传到我的网络服务器,无需扩展名即可保存。

例如.doc将被保存为当前时间(1234567890),但没有扩展名。

这工作正常,我没有这个问题。

我遇到的问题是我喜欢稍后通过电子邮件将文档发送到电子邮件地址。 我喜欢分配原始名称,包括文件的扩展名。

所有数据都保存在我的数据库中。 的名称和扩展名。

因此,例如,我喜欢将此文件"1234567890"发送到电子邮件地址.doc例如。

使用 phpmailer AddStringAttachment

http://phpmailer.worxware.com/index.php?pg=tutorial#3.2

代码

  <html>
   <head>
    <title>My First File Sender</title>
   <meta charset="utf8 ">
  </head>
    <body>
    <?php
      if (!isset($_POST["file"]))
       {
         echo '<form method="POST" action="upload.php" enctype="multipart/form-data"><input type="file" name="fileToUpload" id="fileToUpload"><br><input type="submit" value="Send File"></form>';
      }else {
       /*
        Settings start here
       */
       $target_dir = "files/";
       $name = "John Doe";
       $email = "johndoe@freemail.net";
       $subject = "New File";
       /*
       Settings end here
      */
       $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
       $uploadOk = 1;
       $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
       $msg = '
       Dear  ' . $name . ',<br>
      A new file has been sent, it will be saved in the uploads file.<br><br>
   Thank you,<br>
   Automated System
    ';
      mail($email,$subject,$msg);
      echo "Thank You.";
      }
     ?>


  </body>
  </html>

工作原理

浏览器将检查您是否已经添加了文件。

如果没有:

它将提示您选择一个文件。

如果为真:

它会将文件上传到等于$target_dir的任何内容。

然后向任何$email发送电子邮件。

消息可能如下所示。

亲爱的约翰·多伊,已发送一个新文件,该文件将保存在上传文件中。谢谢自动化系统