2012-05-02 61 views
0

我有页面,用户上传他们文件到我的web服务器得到保存没有扩展名。php发送文件没有扩展名到电子邮件

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

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

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

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

因此,例如,我想将此文件“1234567890”作为example.doc发送到电子邮件地址。

+0

你应该包括代码/你试过的东西。 –

+0

好的。你知道该做什么。什么不行? –

+0

这就是事情。我不知道如何做到这一点。 – Lalajee

回答

0

CODE

<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 = "[email protected]"; 
     $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> 

它是如何工作

浏览器会检查您是否已经添加的文件。

如果不是:

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

如果为true:

这将上传到任何$target_dir等于文件。

然后发送电子邮件到任何$email等于。

该消息可能看起来像这样。

 
Dear John Doe, 
A new file has been sent, it will be saved in the uploads file. 


Thank you, 
Automated System