我尝试上传txt / docx文件并将其转换为pdf

时间:2016-08-26 01:09:37

标签: php html pdf

我正在尝试创建一个程序,在我的文件夹上传txt / docx文件并将其转换为pdf,但每当我打开pdf文件时,它都显示错误:不是pdf或损坏的文件,这是我的代码

//html

<!DOCTYPE html>
<html>
<body>

<form action="trylngnangtry.php" method="post" enctype="multipart/form-data">
Select Text file to Convert:
<input type="file" name="fileToUpload">
<input type="submit" value="Convert" name="submit">
</form>

</body>
</html>

//php

<?php
$target_dir = "C:/xampp/htdocs/mine/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);

if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {

$myfile = fopen("ConvFile.pdf", "w") or die("Unable to open file!");
    $basa = file_get_contents(basename( $_FILES["fileToUpload"]["name"]));
fwrite($myfile, $basa);
fclose($myfile);

echo file_get_contents("ConvFile.PDF");

} else {

$myfile = fopen("ConvFile.pdf", "w") or die("Unable to open file!");
    $basa = file_get_contents(basename( $_FILES["fileToUpload"]["name"]));
fwrite($myfile, $basa);
fclose($myfile);

echo file_get_contents("ConvFile.PDF");
}

?>

0 个答案:

没有答案