if(isset($_POST['sumit']))
{
$con = mysqli_connect("localhost","root","","school");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sname=$_POST['sname'];
$category=$_POST['category'];
$sadd=$_POST['sadd'];
$file_name=$_FILES['file']['name'];
$temp_name=$_FILES['file']['tmp_name'];
$file_size = $_FILES['file']['size'];
$file_type = $_FILES['file']['type'];
$target_path = "Newfolder1";
$sql="SELECT * FROM imagetable WHERE sname='$sname' and sadd='$sadd'and category='$category' and file='$target_path'";
$result1 = mysqli_query($con, $sql);
if(!mysqli_query($con, $sql)){
die( "Could not execute sql: $sql");
}
$row = mysqli_fetch_row($result1);
$file=$row[0];
$pdf=new fpdf();
$pdf->ADDPage();
$pdf->setfont('Arial','B', 16);
$pdf->Image($file,150,25,50,20,$file_type);
$pdf->Cell(0,10,'id',0,1);
$pdf->Cell(0,10,'sadd',0,1);
$pdf->Cell(0,10,'category',0,1);
$pdf->Cell(0,10,'sname',0,1);
$pdf->Output();}
这给了我图像类型,但所有这些都是通过数据库完成的 我的图像类型正在数据库中定义,但我不知道。我正在接受错误。 如果有人能找到错误,请回复
答案 0 :(得分:2)
问题是,您在$file_type
变量(例如image/png
或image/jpeg
)中指定了mime类型,并在Image()
方法中使用了该类型。您应该只指定图像格式。可能的值是(不区分大小写):JPG,JPEG,PNG和GIF。
首先得到图像格式,如下所示:
$image_format = strtolower(pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION));
然后像这样调用Image()
方法:
$pdf->Image($file,150,25,50,20,$image_format);
<强>编辑:强>
像这样更改您的INSERT
查询,
$image_path = $target_path . DIRECTORY_SEPARATOR . $file_name;
if(move_uploaded_file($temp_name, $image_path)) {
$qry="INSERT INTO imagetable (file, sname, category, sadd, type,size, content ) values ('".$image_path."','".$sname."','".$category."','".$sadd."', '".$file_type."','".$file_size."', '".$Content."')";
mysqli_query($con,$qry) or die("error in $qry == ----> ".mysqli_error());
}
并改变你的SELECT
声明,
// your code
$target_path = "Newfolder1" . DIRECTORY_SEPARATOR . $file_name;
$sql="SELECT * FROM imagetable WHERE sname='$sname' and sadd='$sadd'and category='$category' and file='$target_path'";
// your code
答案 1 :(得分:0)
$pdf->Image("image/$user-signature.png" ,100, 213,-300);
此格式适合我。尝试删除$ file并在$ filetype
周围加上引号