我找到了关于在邮件中添加附件的post。问题是如何连接上传的文件与该功能?我必须通过什么?
UPD:
echo '<pre>';
print_r($_FILES);
echo '</pre>';
$uploads_dir = '/uploads'; // It has need rights
$tmp_name = $_FILES["vac_file"]["tmp_name"];
$res = is_uploaded_file($tmp_name); // This is true
$name = $_FILES["vac_file"]["name"];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
echo '$tmp_name: '. $tmp_name . '; $name: ' . $name;
→
Array
(
[vac_file] => Array
(
[name] => LFS.desktop
[type] => application/octet-stream
[tmp_name] => /tmp/phpV417nF
[error] => 0
[size] => 226
)
)
yeah!
Warning: move_uploaded_file(/uploads/LFS.desktop): failed to open stream: No such file or directory in /srv/http/vacancies_attachment.php on line 47 Warning: move_uploaded_file(): Unable to move '/tmp/phpV417nF' to '/uploads/LFS.desktop' in /srv/http/vacancies_attachment.php on line 47 $tmp_name: /tmp/phpV417nF; $name: LFS.desktop
答案 0 :(得分:4)
使用move_uploaded_file()
将文件移动到临时位置;将它从那里附加到邮件中并在之后删除它(或保留它,无论你想做什么)。
有关详细示例,请参阅PHP manual on file uploads。
答案 1 :(得分:3)
您的完整解决方案应如下所示:
1)html
<form method="post" action="myupload.php">
<input type="file" name="uploaded_file" />
<input type="submit" />
</form>
2)myupload.php
<?php
$uploads_dir = '/uploads';
foreach ($_FILES["uploaded_file"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["uploaded_file"]["tmp_name"][$key];
$name = $_FILES["uploaded_file"]["name"][$key];
move_uploaded_file($tmp_name, "$uploads_dir/$name");
}
}
?>