PHP $_FILES['file']['tmp_name']: How to preserve filename and extension?

后端 未结 6 1118
谎友^
谎友^ 2020-12-09 16:25

I am trying to upload a doc file from a form and send it to email. I am using

$_FILES[\'file\'][\'tmp_name\'];

The problem is, it is retur

6条回答
  •  醉梦人生
    2020-12-09 16:52

    Just a suggestion, but you might try the Pear Mail_Mime class instead.

    http://pear.php.net/package/Mail_Mime/docs

    Otherwise you can use a bit of code. Gabi Purcaru method of using rename() won't work the way it's written. See this post http://us3.php.net/manual/en/function.rename.php#97347 . You'll need something like this:

    $dir = dirname($_FILES["file"]["tmp_name"]);
    $destination = $dir . DIRECTORY_SEPARATOR . $_FILES["file"]["name"];
    rename($_FILES["file"]["tmp_name"], $destination);
    $geekMail->attach($destination);
    

提交回复
热议问题