在使用Zend Sutdio10.6設(shè)置斷點(diǎn)并調(diào)試上面這段PHP代碼時(shí)我發(fā)現(xiàn)“if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {”這行代碼里面的代碼塊沒有執(zhí)行,于是查看了超全局變量$_FILES['screenshot']['tmp_name']的值為空,然后我在這行代碼前以JSON格式打印出$_FILES變量的值,如下:<\/span>{\"screenshot\":{\"name\":\"Penguins.jpg\",\"type\":\"\",\"tmp_name\":\"\",\"error\":2,\"size\":0}}<\/pre><\/p>
相應(yīng)的運(yùn)行截圖如下:<\/span><\/span><\/p>
<\/span><\/p>然后我查詢$_FILES['screenshot']['error']為2,上網(wǎng)查詢了一下,關(guān)于$_FILES超級(jí)全局變量的介紹<\/span>大體如下:<\/span><\/span><\/p><\/span><\/span><\/p>PHP編程語(yǔ)言中的常見的$_FILES系統(tǒng)函數(shù)用法有:<\/span><\/p>$_FILES['myFile']['name'] 顯示客戶端文件的原名稱。<\/span><\/p>$_FILES['myFile']['type'] 文件的 MIME 類型,例如\"image\/gif\"。<\/span><\/p>$_FILES['myFile']['size'] 已上傳文件的大小,單位為字節(jié)。<\/span><\/p>$_FILES['myFile']['tmp_name'] 儲(chǔ)存的臨時(shí)文件名,一般是系統(tǒng)默認(rèn)。<\/span><\/p>$_FILES['myFile']['error'] 該文件上傳相關(guān)的錯(cuò)誤代碼。以下為不同代碼代表的意思:<\/span><\/p>0:文件上傳成功。<\/span><\/p>1:超過了文件大小php.ini中即系統(tǒng)設(shè)定的大小。<\/span><\/p>2:超過了文件大小<\/span><\/p>MAX_FILE_SIZE 選項(xiàng)指定的值。<\/span><\/p>3;:文件只有部分被上傳。<\/span><\/p>4:沒有文件被上傳。<\/span><\/p>5:上傳文件大小為0。<\/span><\/p>
另外,查詢PHP參考手冊(cè)關(guān)于move_uploaded_file函數(shù)的介紹如下:<\/span><\/p><\/p>
move_uploaded_file(PHP 4 >= 4.0.3, PHP 5)move_uploaded_file — 將上傳的文件移動(dòng)到新位置說明bool move_uploaded_file ( string $filename , string $destination )本函數(shù)檢查并確保由 filename 指定的文件是合法的上傳文件(即通過 PHP 的 HTTP POST 上傳機(jī)制所上傳的)。如果文件合法,則將其移動(dòng)為由 destination 指定的文件。 這種檢查顯得格外重要,如果上傳的文件有可能會(huì)造成對(duì)用戶或本系統(tǒng)的其他用戶顯示其內(nèi)容的話。 參數(shù)filename上傳的文件的文件名。 destination移動(dòng)文件到這個(gè)位置。 返回值成功時(shí)返回 TRUE。 如果 filename 不是合法的上傳文件,不會(huì)出現(xiàn)任何操作, move_uploaded_file() 將返回 FALSE。 如果 filename 是合法的上傳文件,但出于某些原因無法移動(dòng),不會(huì)出現(xiàn)任何操作, move_uploaded_file() 將返回 FALSE。此外還會(huì)發(fā)出一條警告。 <\/pre>
<\/p>
范例<\/h3>
<\/p>
<\/p>
Example #1 Uploading multiple files<\/strong><\/p><\/p> $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES[\"pictures\"][\"tmp_name\"][$key]; $name = $_FILES[\"pictures\"][\"name\"][$key]; move_uploaded_file($tmp_name, \"$uploads_dir\/$name\"); }}?> <\/pre>原因終于找到了,是因?yàn)槲疑蟼髁艘粋€(gè)超過32768Bytes即32KB大小的Penguins.jpg文件導(dǎo)致出現(xiàn)<\/span>$_FILES['screenshot']['error']為2的錯(cuò)誤,并且$_FILES['screenshot']['tmp_name']為空,move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)函數(shù)調(diào)用時(shí)返回FALSE,if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {?
? ...
?}代碼塊沒有執(zhí)行。<\/span><\/span>
? ? ?<\/p>\n
\n \n \n \n \n <\/div>"}
PHP上傳文件超過文件最大限制羅致無法上傳成功
Jun 13, 2016 pm 12:01 PM
gt
lt
name
quot
screenshot
PHP上傳文件超過文件最大限制導(dǎo)致無法上傳成功
? ? ?最近在學(xué)習(xí)《HeadFirst PHP & MySQL》一書的第5章“使用存儲(chǔ)在文件中的數(shù)據(jù)”,做一個(gè)文件上傳的應(yīng)用時(shí),出現(xiàn)了錯(cuò)誤,就是文件無法成功上傳。這個(gè)問題困擾了我很久,不過還好最后終于解決了。原因是我上傳的圖片文件大小超過了HTML 表單中MAX_FILE_SIZE 選項(xiàng)指定的值32768Bytes即32KB導(dǎo)致無法上傳成功。
? ? 我使用了XAMPP(Apache + MySQL + PHP + Perl)集成開發(fā)包和Zend Studio 10.6作為PHP IDE開發(fā)環(huán)境,另外關(guān)于PHP調(diào)試我采用了XDebug,在Zend Studio10.6中配置Xdebug的PHP調(diào)試環(huán)境我參考了博文Zend Studio 10.5 與 XDebug 調(diào)試| Zend Debugger 說明 Drupal 源代碼 (一)一文。
????? 相應(yīng)的文件上傳示例PHP代碼addscore.php如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Guitar Wars - Add Your High Score</title> <link rel="stylesheet" type="text/css" href="style.css" /></head><body> <h2>Guitar Wars - Add Your High Score</h2><?php require_once 'appvars.php'; require_once 'connectvars.php'; if (isset($_POST['submit'])) { // Grab the score data from the POST $name = $_POST['name']; $score = $_POST['score']; $screenshot = $_FILES['screenshot']['name']; if (!empty($name) && !empty($score) && !empty($screenshot)) { // Move the file to the target upload folder $target = GW_UPLOADPATH . $screenshot; echo json_encode($_FILES); if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die('Error Connecting to MySQL Database!'); // Write the data to the database $query = "INSERT INTO guitarwars VALUES (0, NOW(), '$name', '$score','$screenshot')"; mysqli_query($dbc, $query) or die('Error querying database;'); // Confirm success with the user echo '<p>Thanks for adding your new high score!</p>'; echo '<p><strong>Name:</strong> ' . $name . '<br />'; echo '<strong>Score:</strong> ' . $score; echo '<img src="/static/imghw/default1.png" data-src="/img/2014/07/09/143017574.jpg" class="lazy" alt="Score image" /></p>'; echo '<p><a href="index.php"><< Back to high scores</a></p>'; // Clear the score data to clear the form $name = ""; $score = ""; $screenshot = ""; mysqli_close($dbc); } } else { echo '<p class="error">Please enter all of the information to add your high score.</p>'; } }?> <hr /> <form method="post" enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <input type="hidden" name="MAX_FILE_SIZE" value="32768" /> <label for="name">Name:</label> <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br /> <label for="score">Score:</label> <input type="text" id="score" name="score" value="<?php if (!empty($score)) echo $score; ?>" /><br /> <label for="screeshot">ScreenShot</label> <input type="file" id="screenshot" name="screenshot" /> <hr /> <input type="submit" value="Add" name="submit" /> </form></body> </html>
在使用Zend Sutdio10.6設(shè)置斷點(diǎn)并調(diào)試上面這段PHP代碼時(shí)我發(fā)現(xiàn)“if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {”這行代碼里面的代碼塊沒有執(zhí)行,于是查看了超全局變量$_FILES['screenshot']['tmp_name']的值為空,然后我在這行代碼前以JSON格式打印出$_FILES變量的值,如下:{"screenshot":{"name":"Penguins.jpg","type":"","tmp_name":"","error":2,"size":0}}
相應(yīng)的運(yùn)行截圖如下:

然后我查詢$_FILES['screenshot']['error']為2,上網(wǎng)查詢了一下,關(guān)于$_FILES超級(jí)全局變量的介紹大體如下:
PHP編程語(yǔ)言中的常見的$_FILES系統(tǒng)函數(shù)用法有:$_FILES['myFile']['name'] 顯示客戶端文件的原名稱。$_FILES['myFile']['type'] 文件的 MIME 類型,例如"image/gif"。$_FILES['myFile']['size'] 已上傳文件的大小,單位為字節(jié)。$_FILES['myFile']['tmp_name'] 儲(chǔ)存的臨時(shí)文件名,一般是系統(tǒng)默認(rèn)。$_FILES['myFile']['error'] 該文件上傳相關(guān)的錯(cuò)誤代碼。以下為不同代碼代表的意思:0:文件上傳成功。1:超過了文件大小php.ini中即系統(tǒng)設(shè)定的大小。2:超過了文件大小MAX_FILE_SIZE 選項(xiàng)指定的值。3;:文件只有部分被上傳。4:沒有文件被上傳。5:上傳文件大小為0。另外,查詢PHP參考手冊(cè)關(guān)于move_uploaded_file函數(shù)的介紹如下:
move_uploaded_file(PHP 4 >= 4.0.3, PHP 5)move_uploaded_file — 將上傳的文件移動(dòng)到新位置說明bool move_uploaded_file ( string $filename , string $destination )本函數(shù)檢查并確保由 filename 指定的文件是合法的上傳文件(即通過 PHP 的 HTTP POST 上傳機(jī)制所上傳的)。如果文件合法,則將其移動(dòng)為由 destination 指定的文件。 這種檢查顯得格外重要,如果上傳的文件有可能會(huì)造成對(duì)用戶或本系統(tǒng)的其他用戶顯示其內(nèi)容的話。 參數(shù)filename上傳的文件的文件名。 destination移動(dòng)文件到這個(gè)位置。 返回值成功時(shí)返回 TRUE。 如果 filename 不是合法的上傳文件,不會(huì)出現(xiàn)任何操作, move_uploaded_file() 將返回 FALSE。 如果 filename 是合法的上傳文件,但出于某些原因無法移動(dòng),不會(huì)出現(xiàn)任何操作, move_uploaded_file() 將返回 FALSE。此外還會(huì)發(fā)出一條警告。
范例
Example #1 Uploading multiple files
<?php$uploads_dir = '/uploads';foreach ($_FILES["pictures"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; $name = $_FILES["pictures"]["name"][$key]; move_uploaded_file($tmp_name, "$uploads_dir/$name"); }}?>
原因終于找到了,是因?yàn)槲疑蟼髁艘粋€(gè)超過32768Bytes即32KB大小的Penguins.jpg文件導(dǎo)致出現(xiàn)$_FILES['screenshot']['error']為2的錯(cuò)誤,并且$_FILES['screenshot']['tmp_name']為空,move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)函數(shù)調(diào)用時(shí)返回FALSE,if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)) {?
? ...
?}代碼塊沒有執(zhí)行。? ? ?
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
What are the differences between Huawei GT3 Pro and GT4?
Dec 29, 2023 pm 02:27 PM
Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety
Fix: Snipping tool not working in Windows 11
Aug 24, 2023 am 09:48 AM
Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps
How to Fix Can't Connect to App Store Error on iPhone
Jul 29, 2023 am 08:22 AM
Part 1: Initial Troubleshooting Steps Checking Apple’s System Status: Before delving into complex solutions, let’s start with the basics. The problem may not lie with your device; Apple's servers may be down. Visit Apple's System Status page to see if the AppStore is working properly. If there's a problem, all you can do is wait for Apple to fix it. Check your internet connection: Make sure you have a stable internet connection as the "Unable to connect to AppStore" issue can sometimes be attributed to a poor connection. Try switching between Wi-Fi and mobile data or resetting network settings (General > Reset > Reset Network Settings > Settings). Update your iOS version:
What folder is screenshot?
Feb 27, 2023 am 10:48 AM
screenshot is a folder dedicated to game screenshots. You can use F12 to take screenshots. The default is bmp format. The bmp format is a standard image file format in the Windows operating system and can be supported by a variety of Windows applications.
php提交表單通過后,彈出的對(duì)話框怎樣在當(dāng)前頁(yè)彈出,該如何解決
Jun 13, 2016 am 10:23 AM
php提交表單通過后,彈出的對(duì)話框怎樣在當(dāng)前頁(yè)彈出php提交表單通過后,彈出的對(duì)話框怎樣在當(dāng)前頁(yè)彈出而不是在空白頁(yè)彈出?想實(shí)現(xiàn)這樣的效果:而不是空白頁(yè)彈出:------解決方案--------------------如果你的驗(yàn)證用PHP在后端,那么就用Ajax;僅供參考:HTML code
Is watch4pro better or gt?
Sep 26, 2023 pm 02:45 PM
Watch4pro and gt each have different features and applicable scenarios. If you focus on comprehensive functions, high performance and stylish appearance, and are willing to bear a higher price, then Watch 4 Pro may be more suitable. If you don’t have high functional requirements and pay more attention to battery life and reasonable price, then the GT series may be more suitable. The final choice should be decided based on personal needs, budget and preferences. It is recommended to carefully consider your own needs before purchasing and refer to the reviews and comparisons of various products to make a more informed choice.
How to optimize iPad battery life with iPadOS 17.4
Mar 21, 2024 pm 10:31 PM
How to Optimize iPad Battery Life with iPadOS 17.4 Extending battery life is key to the mobile device experience, and the iPad is a good example. If you feel like your iPad's battery is draining too quickly, don't worry, there are a number of tricks and tweaks in iPadOS 17.4 that can significantly extend the run time of your device. The goal of this in-depth guide is not just to provide information, but to change the way you use your iPad, enhance your overall battery management, and ensure you can rely on your device for longer without having to charge it. By adopting the practices outlined here, you take a step toward more efficient and mindful use of technology that is tailored to your individual needs and usage patterns. Identify major energy consumers
What should I do if php cannot get the name?
Nov 24, 2022 am 09:56 AM
PHP cannot get the name because when the name and id values ??of the form element are different, the browser cannot recognize it. The solution: 1. Check whether some form elements and frame elements use name; 2. Check only Elements that can be assigned ID but not name; 3. For multi-select box checkbox, you can use "join(',', $__POST['name'])" to form data.
See all articles