我是PHP的新手,我一直在尝试使用PHP制作图像上传器,但我遇到了问题,它只上传了3张图片然后停止了,我不知道为什么会这样。
这是HTML代码
<?php
require ('script.php');
$classObj = new news ;
$classObj->dbcon();
?>
<!DOCTYPE html>
<html>
<head>
<title>test drive</title>
</head>
<body>
<form action="" method="POST" enctype="multipart/form-data">
<input type="text" name="username" placeholder="username"></input>
<input type="text" name="firstname" placeholder="firstname"></input>
<input type="file" name="file"></input>
<input type="submit" name="submit"></input>
</form>
<?php $classObj->sent(); ?>
</body>
</html
这是PHP代码
function upload(){
if (isset($_POST['submit'])) {
$this->img_name = $_FILES['img']['name'];
$this->img_size = $_FILES['img']['size'];
$this->img_tmpname = $_FILES['img']['tmp_name'];
$this->img_path = basename($this->img_name);
$this->img_ext = $_FILES['img']['type'];
$this->img_dir = 'upload/'.$this->img_path;
if ($this->img_ext != "jpg" || $this->img_ext != "JPG" ||$this->img_ext != "png" ||$this->img_ext != "PNG" ||$this->img_ext != "JPEG" ||$this->img_ext != "jpeg" ) {
if (file_exists("$this->img_dir")) {
echo "<p> sorry file exist</p>";
exit();
}else{
move_uploaded_file( $this->img_tmpname, $this->img_dir);
echo '<p>succesfull</p>';
echo $_FILES['img']['size'];
header("location:$this->img_dir");
}
}else{
echo "invalid pics";
}
}
}
答案 0 :(得分:1)
你的名字错过了。将字段名称更改为img,因为您在PHP脚本中调用它的值。
<input type="file" name="img"></input>