Php OOP在文件夹中上载图像
我正在工作上传图片到文件夹,应用程序工作,但当我第一次打开页面上传图片时,我有一些错误消息,当我上传图片时,没有错误消息结束,我可以上传很多我想要的没有错误。当我再次单击或重新加载页面时,第一次出现错误,并且在第一次上传错误后消失 我有文件夹图像Php OOP在文件夹中上载图像,php,Php,我正在工作上传图片到文件夹,应用程序工作,但当我第一次打开页面上传图片时,我有一些错误消息,当我上传图片时,没有错误消息结束,我可以上传很多我想要的没有错误。当我再次单击或重新加载页面时,第一次出现错误,并且在第一次上传错误后消失 我有文件夹图像 File: pictureupload.php File: classimage.php pictureupload.php的代码是 <?php include_once 'classimage.php'; $img= new images()
File: pictureupload.php
File: classimage.php
pictureupload.php的代码是
<?php
include_once 'classimage.php';
$img= new images();
$img->uploadImages();
?>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<input type="file" name="picture" >
<br><br>
<input type="submit" name="upload" value="Upload Picture">
</form>
</body>
</html>
此错误来自文件classimage.php
$this->fileName = $_FILES['picture']['name']; - line12
$this->fileTmp = $_FILES['picture']['tmp_name']; - line 13
$this->fileSize = $_FILES['picture']['size']; - line 14
$this->fileError = $_FILES['picture']['error']; - line 15
$this->fileType =$_FILES['picture']['type']; - line 16
嗯
$\u文件['picture']
不会在您第一次加载页面时设置,因为您没有上载任何图像,因此当您执行以下操作时:
$img= new images();
在构造函数中,您要从尚未设置的$_文件['picture']获取日期
您应该先检查$\u文件数组,然后再执行其他操作
public function __construct()
if (count($_FILES) > 0) {
// constructor code.
}
}
如果在图像上载页面上包含该类,则仅当在
\u构造()中正确分配了$\u文件时,才应调用新图像()
。换句话说,显示错误是因为在用户提交页面之前,没有任何$\u文件可供参考。
$img= new images();
public function __construct()
if (count($_FILES) > 0) {
// constructor code.
}
}