에 이미지를 업로드하고 있습니다. 응용 프로그램이 작동하지만, 이미지를 업로드 할 때 처음 페이지를 열면 이미지를 업로드 할 때 몇 가지 오류 메시지가 나타납니다. 오류 메시지 끝 오류없이 원하는만큼 업로드 할 수 있습니다. 다시 클릭하거나 처음 페이지를 새로 고침하면 오류가 발생하고 처음으로 오류를 업로드 한 후 사라집니다. 나는이가 내가 사진을 업로드 할 때OOP 폴더
내가 폴더 이미지가 pictureupload.php에 대한
File: pictureupload.php
File: classimage.php
코드가 classimage.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>
코드
<?php
class images
{
protected $fileName;
protected $fileTmp;
protected $fileType;
protected $fileSize;
protected $fileError;
public function __construct()
{
$this->fileName = $_FILES['picture']['name'];
$this->fileTmp = $_FILES['picture']['tmp_name'];
$this->fileSize = $_FILES['picture']['size'];
$this->fileError = $_FILES['picture']['error'];
$this->fileType =$_FILES['picture']['type'];
}
public function uploadImages()
{
//if Button push
if(isset($_POST['upload']) && $_POST['upload']=='Upload Picture')
{
//get type after .
$kabom = explode(".", $this->fileName);
//get image type
$fileExtnsion = end($kabom);
$fileName = time().rand().".".$fileExtnsion;
if(!$this->fileTmp)
{
echo "Error: Please browse for a file before clicking the upload button";
exit();
}
elseif ($this->fileSize > 5242880)
{
echo "Error: Your file was large than 5MB";
unlink($this->fileTmp);
exit();
}
elseif (!preg_match("/.(gif|jpg|png)$/i", $this->fileName))
{
echo "ERROR: Your image was not .gif, .jpg, or .png.";
unlink($this->fileTmp);
exit();
}
elseif ($this->fileError==1)
{
echo "Error.Please try again";
exit();
}
$movePicture = move_uploaded_file($this->fileTmp, "images/$fileName");
if($movePicture == false)
{
echo "Error File not uploaded.";
exit();
}
}
}
}
?>
처음이다 오류
Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 12
Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 13
Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 14
Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 15
Notice: Undefined index: picture in C:\xampp\htdocs\www\imageupload\test\classimage.ph p on line 16
이 오류는 실행할 때 따라서,
$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
만')()'(A'새로운 이미지를 요구한다 . 즉, 사용자가 페이지를 제출할 때까지 참조 할 '$ _FILES'가 없기 때문에 오류가 표시됩니다. – sbeliv01