我有一个php表格,并使用html2pdf(TCPDF)。当我使用已经包含在表单中的文本和图像时,php表单可以使用,但是现在我想附加图像并将其包含在pdf文件中。
我正在使用的代码获得文件名。
附加我正在使用的图像$<span><input type="file" name="foto"></span>
并将其包含在pdf文件中,我使用以下代码$foto = $_POST['foto'];
$content .= '<img src='.$foto.'with=200 height=auto>';
对不起,我英语不好!问候丹尼尔
像这样正常地上传HTML文件:
<form method="post" enctype="multipart/form-data">
<label>Deine Datei ;) :
<input name="fileUpload" type="file" accept="image/*">
</label>
<label>Your Name:
<input name="userName" type="text" accept="image/*">
</label>
<button type="submite" name="submite">Upload</button>
</form>
在PHP端,您必须移动文件:
if(isset($_POST["submit"])) {
$userName = $_POST['userName']; // the normale methode
$check = getimagesize($_FILES["fileUpload"]["tmp_name"]);
if($check !== false) {
$temp_path_to_file = $_FILES['fileUpload']['tmp_name'];
$file_content = file_get_contents($temp_path_to_file);
// and now past your image to your PDF.
// if you want to save the image on the server you must move it with this (its not necessary if you want only to past it in your PDF)
if(move_uploaded_file($temp_path_to_file, '/my/image/folder/image_'.uniqid() . '.' . pathinfo($filename, PATHINFO_EXTENSION);
}
}
编辑:对于您的示例,您必须将$file_content
转换为base64字符串。比您可以将其粘贴到图像中:
$base64 = 'data:image/' . pathinfo($filename, PATHINFO_EXTENSION) . ';base64,' . base64_encode($file_content);
echo '<img src="'. $base64 .'" style="with: 200; height: auto">';