我想让用户上传PDF到我网站上的文件夹。 (注意:这是为了学习的目的,所以安全性是没有必要的)下面的代码在提交时不会回应回应。我希望将pdf上传到的文件夹与php脚本位于同一目录中,是否有可能我错误地引用了该文件夹?我很感激。通过PHP上传文件到网站上的文件夹
<form method = "POST" action = "<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data" method="post">
Email:<br /> <input type = "text" name="email" value=""/><br />
Resume:<br /><input type = "file" name="resume" value=""/><br />
<p><input type="submit" name ="submit" value="Submit Resume" /></p>
</form>
if(isset($_POST['submit']))
{
define ("FILEREPOSITORY","./resume/");
if (is_uploaded_file($_FILES['resume']['tmp_name'])) {
if ($_FILES['resume']['type'] != "application/pdf") {
echo "<p>Resume must be in PDF Format.</p>";
}
}else {
$name = $_POST['email'];
$result = move_uploaded_file($_FILES['resume']['tmp_name'], FILEREPOSITORY."/$name.pdf");
if ($result == 1) {
echo "<p>File successfully uploaded.</p>";
}
else {
echo "<p>There was a problem uploading the file.</p>";
}
}
}
属性名称和值之间不应有空格。 'type =“text”'应该是'type =“text”'。 – Kenaniah
如果您将表单发布到*完全相同的*网址,请忽略该操作。它将默认为用于提取页面的请求URI。 – Kenaniah
@Kenaniah这实际上并不重要(对于你的第一个评论和你的第二个评论)。 – jli