我正在努力让图片上传工作......
我有更多的表单元素,但我认为这是唯一重要的部分
<form name="register" method="post" action="profiles.php" onSubmit="return validateForm()">
<td class="col1">Profile Picture</td>
<td class="col2">
<input type="file" name="file" id="file">
</td>
将其传递给profiles.php
profiles.php包含传递的表单的所有变量....期望那个。 我收到错误“通知:未定义的索引:文件”
这基本上是脚本中使用的所有文件......
$target = "files/";
echo $_FILES['file']['name'];
//$image = basename($_FILES['file']['name']);
//echo $image;
$name = str_replace(' ', '_', $image);
$target .= strtolower($name . uniqid());
if(move_uploaded_file($_FILES['file']['tmp_name'], $target))
{
//echo $firstName, $lastName, $UserName, $email, $DOB, $join, $gender, $likes;
//just a test to see if they were working.
addEntry($firstName, $lastName, $UserName, $Password, $email, $DOB, $join, $gender, $likes, $description, $newlike, $target);
}
答案 0 :(得分:3)
尝试将enctype =“multipart / form-data”添加到html表单标记中。即:
<form enctype="multipart/form-data">
答案 1 :(得分:1)
enctype="multipart/form-data"
中缺少<form>
。
答案 2 :(得分:1)
很可能您还没有在表单中定义文件上传元素“文件”。
<input type="file" name="file" id="file" />
另外,请确保您的表单enctype
为"multipart/form-data"
<form action="upload.php" method="post" enctype="multipart/form-data">
答案 3 :(得分:-1)
兄弟enctype="multipart/form-data"