Php-PHP file upload problem $ _ FILES ['file'] ['error']

Source: Internet
Author: User
Tags php file upload php website
During this period of time, I have been reading "HeadFirstPHP & amp; MySQL". This book is very good. I learned how to develop a PHP website step by step and have been typing code step by step. now I can see page 487, when testing the file upload function, we found the previous editprofile. if ($ _ FILES [& #39; file & #39;] [& #39; error & #39;] 0) {always reports an error: Validateandmovetheuploadedpicturefile, ifnecessaryif (! Empty (phpfile

During this time, I have been reading "Head First PHP & MySQL". This book is very good. I will teach you how to develop one step by step.
The PHP website keeps typing code step by step. now we can see page 487. when testing the file upload function, we find that
If ($ _ FILES ['file'] ['error'] = 0) in editprofile. php {always reports an 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 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 was a problem uploading your picture.

';
}
}
}
Else {
// The new picture file is not valid, so delete the temporary file and set the error flag
@ Unlink ($ _ FILES ['new _ picture '] ['tmp _ name']);
$ Error = true;
Echo'

Your picture must be 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 picture 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 = '$gender', " .        " 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 you like to view your profile?

'; mysqli_close($dbc); exit(); } else { echo '

You must enter all of the profile data (the picture is optional).

'; }}

When you modify the login user information and click the button

The error message is displayed, and the information in the database has not changed !!!! Notice: Undefined index: file in D: \ phpStudy \ WWW \ Mismatch \ editprofile. php on line 44 row 44th: if ($ _ FILES ['file'] ['error'] = 0) {what is the cause? how can this problem be solved ?? The code is provided on the official website of the original book and is correct.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.