日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

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

發布時間:2025/3/21 php 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 php files上传错误,php-PHP上传文件的问题$_FILES['file']['error'] 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這段時間一直在啃《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) { 請問這是什么原因,怎么解決??代碼完全是原書官網提供的,沒有寫錯

總結

以上是生活随笔為你收集整理的php files上传错误,php-PHP上传文件的问题$_FILES['file']['error']的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。