我正在尝试制作一个网页以使用 xpdf 将 pdf 转换为文本文件。
下面是使用 xampp 在 Windows 上执行此操作的 php 代码。
<?php
$filename = array();
$filename ="/Applications/XAMPP/xamppfiles/htdocs/abc/test.pdf";//Path of the file
//while ($filename = readdir($dir)) {
if (eregi("\.pdf",$filename)){
$content = shell_exec('/usr/local/bin/pdftotext -raw'.' '.$filename.' -');//$content stores the content of the pdf as string
$read =basename($filename,".pdf");//extracting file name
$testfile = "$read.txt";//changing extension of filename
$file = fopen("/Applications/XAMPP/xamppfiles/htdocs/".$testfile,"w");// creates new file of the same name in at the given location
fwrite($file, $content);//writes content to file
if (filesize($testfile)==0){} //checks if file null
else{
$text = fread($file,filesize($testfile));
fclose($file);
echo "</br>"; echo "</br>";
}
}?>
现在我想在 linux VPS 上运行它。
我有一个具有 SSH 访问权限的 Cent OS VPS。我已经安装了 zpanel、xpdf(使用 yum install xpdf)。
现在我想,当我在浏览器中打开此 URL“www.website.com/convert.php”时,public_html 文件夹中的 test.pdf 文件应转换为同一文件夹中的 test.txt。
那么,我应该在 convert.php 中编写什么代码?