php-PHP上传文件的问题$_FILES['file']['error']

WBOY
풀어 주다: 2016-06-02 11:32:23
원래의
1460명이 탐색했습니다.

phpfile

这段时间一直在啃《Head First PHP & MySQL》,这本书非常好,一步步教授怎么开发一个
PHP网站,一直照着一步步地敲代码,现在看到487页,在测试上传文件功能时,发现前面
的editprofile.php里面的 if ($_FILES['file']['error'] == 0) { 老是报错:
// 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 ($new_picture_width 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.

';
}
}
<code>// 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 '<p>Your profile has been successfully updated. Would you like to <a href="viewprofile.php">view your profile</a>?</p>';    mysqli_close($dbc);    exit();  }  else {    echo '<p class="error">You must enter all of the profile data (the picture is optional).</p>';  }}</code>
로그인 후 복사

修改登录用户的信息并点击按钮时
图片说明

<code>就会显示下图的错误信息,而且数据库里面的信息根本没有改变!!!!Notice: Undefined index: file in D:\phpStudy\WWW\Mismatch\editprofile.php on line 44第44行是: if ($_FILES['file']['error'] == 0) { 请问这是什么原因,怎么解决??代码完全是原书官网提供的,没有写错</code>
로그인 후 복사
관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿