它不会传递变量吗?文件 php
我正在尝试使图像上传工作...
我有更多的表单元素,但我认为这
<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);
}
I'm trying to make an image upload work...
I have a lot more elements of the form but I figure this the only important part
<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>
This is passed onto profiles.php
profiles.php has all the variables of the form passed through....expect for that one.
I get the error "Notice: Undefined index: file"
This is basically all file is used for in the script...
$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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试将 enctype="multipart/form-data" 添加到您的 html 表单标记中。 IE:
Try adding enctype="multipart/form-data" to your html form tag. Ie:
您的
You lack
enctype="multipart/form-data"
in your<form>
.您很可能没有在表单中定义文件上传元素“file”。
另请确保表单的
enctype
为"multipart/form-data"
Most likely you have not defined the file upload element 'file' in your form.
Also make sure your form's
enctype
is"multipart/form-data"
兄弟
enctype="multipart/form-data"
Bro
enctype="multipart/form-data"