gpt4 book ai didi

php - 使用高级php上传图片

转载 作者:行者123 更新时间:2023-11-30 23:06:23 25 4
gpt4 key购买 nike

我正在使用 php 开发基于 oops 的项目,当我上传一张图片时,它没有上传我想与这张图片一起上传的信息。在这里,我连接 Controller 页面,我创建对象以上传数据库中的图像和信息。

html页面代码

<?php
include('include/control.php');
include('include/connect.php');
error_reporting(0);
if(count($_FILES) > 0){
if(is_uploaded_file($_FILES['image']['tmp_name'])){
$i=addslashes(file_get_contents($_FILES['image']['tmp_name']));
$j=getimagesize($_FILES['image']['tmp_name']);
$objectNew=new add;
if(isset($_POST['submit'])){

$info1=$_POST['info1'];
$info2=$_POST['info2'];
$info3=$_POST['info3'];
$info4=$_POST['info4'];
$info5=$_POST['info5'];

$imagetype=$i;
$imageData=$j;
$ob=$objectNew->addInfo($imagetype,$imagedata,$info1,$info2,$info3,$info4,$info5);
}
}
}
?>

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
add info<br />
<form name="form" enctype="multipart/form-data" action="" method="post">
<input type="text" name="info1" /><br />
<input type="text" name="info2" /><br />
<input type="text" name="info3" /><br />
<input type="text" name="info4" /><br />
<input type="text" name="info5" /><br />
<input type="file" name="image"/><br />
<input type="submit" name="submit" />
</form>
</body>
</html>

Controller 代码

 function addInfo($imagetype,$imagedata,$info1,$info2,$info3,$info4,$info5)
{
$addI=$this->conn->prepare('insert into `addinfo` (imagetype,image,info1,info2,info3,info4,info5) VALUES (?,?,?,?,?,?,?) ');
$addI->bind_param("sbsssss",$imagetype,$imagedata,$info1,$info2,$info3,$info4,$info5) ;
$addI->execute();
}

最佳答案

这只是一个建议。您可以将“required”属性添加到您的输入中,这样如果它为空就不会被提交。这适用于最新的浏览器

你的代码

<input type="text" name="info1" /><br />
<input type="text" name="info2" /><br />

可以

<input type="text" name="info1" required /><br />
<input type="text" name="info2" required /><br />

关于php - 使用高级php上传图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21697328/

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