我正在尝试使图像上传工作...
我有更多的表格元素,但我认为这是唯一重要的部分
<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>
这将传递到配置文件中.php
配置文件.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);
}
尝试将enctype="multipart/form-data"添加到您的html表单标签中。即:
<form enctype="multipart/form-data">
你的<form>
缺乏enctype="multipart/form-data"
。
很可能
您没有在表单中定义文件上传元素"file"。
<input type="file" name="file" id="file" />
还要确保表单的enctype
"multipart/form-data"
<form action="upload.php" method="post" enctype="multipart/form-data">
Bro enctype="multipart/form-data"