Phpfile
This time has been gnawing "Head first PHP & MySQL", this book is very good, step by step professor how to develop a
PHP website, always follow the code, and now see 487 page, in the test upload file function, found the front
Editprofile.php inside if ($_files[' file ' [' error '] = = 0) {Always error:
Validate and move the uploaded picture file, if necessary
if (!empty ($new _picture)) {
if (($new _picture_type = = ' image/gif ') | | ($new _picture_type = = ' image/jpeg ') | | ($new _picture_type = = ' image/pjpeg ') | |
($new _picture_type = = ' Image/png ')) && ($new _picture_size > 0) && ($new _picture_size <= mm_maxfilesize) &&
($new _picture_width <= mm_maximgwidth) && ($new _picture_height <= mm_maximgheight)) {
if ($_files[' file ' [' error '] = = 0) {
Move the file to the target upload folder
$target = Mm_uploadpath. basename ($new _picture);
if (Move_uploaded_file ($_files[' new_picture ' [' tmp_name '], $target)) {
The new picture of file move was successful, now make sure any old picture is deleted
if (!empty ($old _picture) && ($old _picture! = $new _picture)) {
@unlink (Mm_uploadpath. $old _picture);
}
}
else {
The new picture file move failed, so delete the temporary file and set the error flag
@unlink ($_files[' new_picture ' [' tmp_name ']);
$error = true;
Echo '
Sorry, there is a problem uploading your picture.
';
}
}
}
else {
The new picture file isn't valid, so delete the temporary file and set the error flag
@unlink ($_files[' new_picture ' [' tmp_name ']);
$error = true;
Echo '
Your picture must is a GIF, JPEG, or PNG image file no greater than '. (mm_maxfilesize/1024).
' KB and '. Mm_maximgwidth. ' X '. Mm_maximgheight. ' Pixels in size.
';
}
}
Update the profile data in the Databaseif (! $error) {if (!empty ($first _name) &&!empty ($last _name) && !empty ($gender) &&!empty ($birthdate) &&!empty ($city) &&!empty ($state)) {//Only set the PI Cture column If there is a new picture if (!empty ($new _picture)) {$query = "UPDATE mismatch_user SET first_name = ' $first _name ', last_name = ' $last _name ', gender = ' $gender ', '. "birthdate = ' $birthdate ', city = ' $city ', state = ' $state ', picture = ' $new _picture ' WHERE user_id = '". $_session[' user_id '. "'"; } else {$query = "UPDATE mismatch_user SET first_name = ' $first _name ', last_name = ' $last _name ', gender = ' $gende R ', ". "birthdate = ' $birthdate ', city = ' $city ', state = ' $state ' WHERE user_id = '". $_session[' user_id '. "'"; } mysqli_query ($dbc, $query); Confirm success with the user echo 'Your profile has been successfully updated. Would to view your profile?
'; Mysqli_close ($DBC); Exit (); } else {echo 'You must enter all of the profiles data (the picture is optional).
'; }}
When you modify the login user's information and click the button
就会显示的错误信息,而且数据库里面的信息根本没有改变!!!!Notice: Undefined index: file in D:\phpStudy\WWW\Mismatch\editprofile.php on line 44第44行是: if ($_FILES['file']['error'] == 0) { 请问这是什么原因,怎么解决??代码完全是原书官网提供的,没有写错