这就是我处理表单的方式:
# Create the message
# ----------------------------------------------------------------
$name = $_POST['name'];
$email = $_POST['email'];
$title = $_POST['title'];
$course = $_POST['course'];
$file = $_POST['file'];
$message = "Name: ".$name."\n";
$message .= "Email: ".$email."\n\n";
$message .= "Title of Article: ".$title."\n";
$message .= "Program: ".$course."\n\n";
$message .= "Additional Info: ".$info;
# Upload temporary files
# ----------------------------------------------------------------
$uploaddir = '/home/public/uploads/';
$uploadfile = $uploaddir . basename($_FILES['file']['name']);
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile) == false) {
echo 'Could not move file';
exit;
}
if ($_FILES['file']['type'] != "application/pdf") {
echo 'Not a pdf file';
unlink($uploadfile);
exit;
}
最终产品希望发送一封电子邮件,其中包含该文件作为附件。现在我失败并得到我内置的“无法移动文件”消息。有一个明显的原因吗? $file
是我从HTML(input type="file"
)
答案 0 :(得分:3)
两件事:
1.表单是否设置为:
<form method="POST" enctype="multipart/form-data" action="INSERT ACTION">
2。您发布文件的文件夹是否设置为777?
答案 1 :(得分:2)
您的表单需要设置相应的enctype
属性,即
<form enctype="multipart/form-data" method="post" action=... >
一些建议......
$_POST['file']
值中得到任何有用的东西(或根本没有)。对所有上传的文件数据使用$_FILES
数组。