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);
}
Try adding enctype="multipart/form-data" to your html form tag. Ie:
<form enctype="multipart/form-data">
您在<form>
缺少enctype="multipart/form-data"
。
Most likely you have not defined the file upload element 'file' in your form.
<input type="file" name="file" id="file" />
Also make sure your form's enctype
is "multipart/form-data"
<form action="upload.php" method="post" enctype="multipart/form-data">
兄弟enctype="multipart/form-data"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.