PHP不能从HTML表单上传文件 [英] PHP can't upload file from HTML form
本文介绍了PHP不能从HTML表单上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
This is how I handle my form:
# 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
)
The end product is hopefully sending an email with the file as an attachment. Right now I'm failing and getting the "Could not move file" message I built in. Is there an obvious reason why? $file
is what I get from a file dialog in HTML (input type="file"
)
推荐答案
两件事情:
1.表单设置为:
Two things:
1. Is the form set to:
<form method="POST" enctype="multipart/form-data" action="INSERT ACTION">
2。发布文件的文件夹是否设置为777?
2. Is the folder your posting the file to, is it set to 777?
这篇关于PHP不能从HTML表单上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文