gpt4 book ai didi

php - 在第 35 行通知 : Undefined index: $error in C:\wamp\www\btb_sandbox\upload_2. php

转载 作者:行者123 更新时间:2023-12-03 08:28:52 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Reference - What does this error mean in PHP?

(37 个回答)


6年前关闭。




我有下面说明的这种错误,我对此并不完全了解。如果我按下上传按钮而不选择文件!

注意: undefined index :第 35 行 C:\wamp\www\btb_sandbox\upload_2.php 中的 $error

<?php
// In an application, this could be moved to a config file
$upload_errors = array(
// http://www.php.net/manual/en/features.file_upload.errors.php
UPLOAD_ERR_OK => "No errors.",
UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.",
UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.",
UPLOAD_ERR_PARTIAL => "Partial upload.",
UPLOAD_ERR_NO_FILE => "No file.",
UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension."
);
if(isset($_POST['submit']))
{
// process the form data
$tmp_file = $_FILES['file_upload']['tmp_name'];
$target_file = basename($_FILES['file_upload']['name']);
$upload_dir = "uploads";

// You will probably want to first use file_exists() to
// make sure there isn't already a file by the same name

// move_uploaded_file will return false if $tmp_file is
// not a valid upload file or if it cannot be moved for
// any same name
if(isset($_FILES['file_upload']) || isset($_FILES['file_upload']['error']))
{

if(move_uploaded_file($tmp_file, $upload_dir."/".$target_file))
{
$message = "File uploaded successfully.";
} else {
$error = $_FILES['file_upload']['error'];
$message = $upload_errors['$error'];
// echo "<pre>";
// print_r($_FILES['file_upload']);
// echo "</pre>";
// echo "<hr />";

}
}
}
?>
<html>
<head>
<title>Upload</title>
</head>
<body>

<?php
// The maximum file size (in bytes) must be declared before the file input field
// and can't be larger than the setting for upload_max_filesize in php.ini.
//
// This form value can be manipulated. You should still use it, but you rely
// on upload_max_filesize as the absolute limit.
//
// Think of it as a polite declaration: "Hey PHP, here comes a file less than X..."
// PHP will stop and complain once X is exceeded.
//
// 1 megabyte is actually 1,048,576 bytes.
// You can round it unless the precision matters.
?>

<?php if(!empty($message)) { echo "<p>{$message}</p>"; } ?>
<form action="upload_2.php" enctype="multipart/form-data" method="POST">

<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="file" name="file_upload" />

<input type="submit" name="submit" value="Upload" />
</form>

</body>
</html>

请帮助我,并详细告诉我!

最佳答案

你显然犯了一个错误。在文档 (http://php.net/manual/en/features.file-upload.errors.php) 中,您会发现:

UPLOAD_ERR_INI_SIZE

并且您确实在脚本中指定了:
UPLOAD_ERR_INT_SIZE

这就是脚本告诉你这个常量不存在的原因:)

关于php - 在第 35 行通知 : Undefined index: $error in C:\wamp\www\btb_sandbox\upload_2. php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30298594/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com