我有一个表单,您可以在其中上传图像,然后使用php将其保存到服务器上的文件夹中。 我将输入表单的其他数据存储在xml文件中,也使用php。我现在希望能够将pdf文件/ pdf-data存储在此xml文件中以供以后使用(该表单充当模板,我后来想要将整个信息存储在另一个文件中并将其显示到用户)。 我读到了有关Base64编码等的内容,但我不确定这是否也适用于PDF文件,因为我所能找到的只是如何为图像执行此操作,或者是否有更简单的方法来执行此操作我的情况?
编辑:这是HTML:
<form method="post" action="profile.php" enctype="multipart/form-data">
<input type="hidden" name="create_xml" value="true">
<label for="name">Name: </label><br>
<input type="text" name="name"><br>
<label for="email">E-mail: </label><br>
<input type="text" name="email"><br>
<label for="textbox">Write something: </label><br>
<textarea name="textbox" rows="5" cols="40"></textarea><br>
<label for="fileToUpload">Upload a PDF-file: </label>
<input type="file" name="fileToUpload" id="file-select">
<input type="text" name="filename" placeholder="Enter the name of your file"><br>
<input type="submit" value="submit" name="submit">
</form>
将数据保存到xml文件的php:
if(isset($_POST['create_xml'])) {
$xml = new DOMDocument();
$newProfile = $xml->createElement('Profile');
$xml->appendChild($newProfile);
$name = $xml->createElement('Name', $name);
$newProfile->appendChild($name);
$email = $xml->createElement('EMail', $emailaddress);
$newProfile->appendChild($email);
$textbox = $xml->createElement('Text', $text);
$newProfile->appendChild($textbox);
$xml->formatOutput = true;
$xml->saveXML();
$xml->save($filename.".xml");
}
答案 0 :(得分:0)
如果要在DB中插入数据时生成xml:
if($this->input->post('submit')){
$name = $_POST['name'];
$email = $_POST['email'];
$filename = $_POST['filename'];
$year = gmdate("Y");
if($_FILES){
$_FILES['fileToUpload']['name'] = $files['fileToUpload']['name'];
$_FILES['fileToUpload']['type'] = $files['fileToUpload']['type'];
$_FILES['fileToUpload']['tmp_name'] = $files['fileToUpload']['tmp_name'];
$_FILES['fileToUpload']['error'] = $files['fileToUpload']['error'];
$_FILES['fileToUpload']['size'] = $files['fileToUpload']['size'];
$ext = pathinfo($_FILES['fileToUpload']['name'], PATHINFO_EXTENSION);
$mtime = uniqid(microtime());
$uniqueid = substr($mtime, 2, 8);
$pdfname = $uniqueid . '.' . $ext; // pdf file encrypt name here which need to save
move_uploaded_file($_FILES['fileToUpload']['tmp_name'], 'uploads/' . $pdfname);
}
//Your insert query here remember here you should add $pdfname as pdflink
// If successful insertion than
$xml = new DOMDocument();
$newProfile = $xml->createElement('Profile');
$xml->appendChild($newProfile);
$name = $xml->createElement('Name', $name);
$newProfile->appendChild($name);
$email = $xml->createElement('EMail', $email);
$newProfile->appendChild($email);
$textbox = $xml->createElement('Text', $filename);
$newProfile->appendChild($textbox);
$pdflink = $xml->createElement('Text', $pdfname);
$newProfile->appendChild($pdflink);
$xml->formatOutput = true;
$xml->saveXML();
$xml->save($filename.".xml");
}