php-PHP上傳檔案的問題$_FILES['file']['error']

來源:互聯網
上載者:User
關鍵字 php file
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 <= 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).

'; }}

修改登入使用者的資訊並點擊按鈕時

就會顯示的錯誤資訊,而且資料庫裡面的資訊根本沒有改變!!!!Notice: Undefined index: file in D:\phpStudy\WWW\Mismatch\editprofile.php on line 44第44行是: if ($_FILES['file']['error'] == 0) { 請問這是什麼原因,怎麼解決??代碼完全是原書官網提供的,沒有寫錯
  • 相關文章

    聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.