我在下面的脚本中使用 imagemagic/ghostscript 来提取 pdf 文件的第一页并将其转换为 jpg 格式,然后我使用 html 表单将 jpg 图片与 pdf 文件和其他信息一起上传到我的 wamp 服务器。但令我惊讶的是,它上传了一些pdf文件并进入确认页面,只有在上传成功时才会激活。但对于某些人来说,它会返回 $err 消息。你能帮帮我吗?
<?php include ('head.php');
include ('connect.php');
if(isset($_POST['submit'])) {
$pdfDirectory = "pdf/";
$thumbDirectory = "pdfimage/";
//get the name of the file
$filename = basename( $_FILES['pdf']['name'], ".pdf");
//remove all characters from the file name other than letters, numbers, hyphens and underscores
$filename = preg_replace("/[^A-Za-z0-9_-]/", "", $filename).".pdf";
//name the thumbnail image the same as the pdf file
$thumb = basename($filename, ".pdf");
$title=$_POST['title'] ;
$author= $_POST['author'] ;
$pub = $_POST['pub'];
$abstract= $_POST['abstract'] ;
$year= $_POST['year'] ;
$category= $_POST['cat'] ;
if(move_uploaded_file($_FILES['pdf']['tmp_name'], $pdfDirectory.$filename)){
//the path to the PDF file
$pdfWithPath = $pdfDirectory.$filename;
//add the desired extension to the thumbnail
$thumb = $thumb.".jpg";
//execute imageMagick's 'convert', setting the color space to RGB and size to 200px wide
exec("convert \"{$pdfWithPath}[0]\" -colorspace RGB -background white -geometry 200 -flatten $thumbDirectory$thumb");
//show the image
//echo "<p><a href=\"$pdfWithPath\"><img src=\"pdfimage/$thumb\" alt=\"\" /></a></p>";
$imagez = "pdfimage/$thumb";
$query ="INSERT INTO books (title, author, publisher, abstract, year, category, book, bkimage) VALUES ('".$title."', '".$author."', '".$pub."', '".$abstract."', '".$year."', '".$category."', '".$filename."', '".$imagez."')" ;
$result = mysql_query($query);
if (!$result) {
$err = "Could not Add to library at this time";
} else {
header('Location:confirm.php');
}
}
}
?>
将书籍添加到图书馆
标题 作者 出版商 摘要 年份类别选择...建筑 建筑工程 土木工程 计算机 电气工程 土地测量 综合管理 机械工程 数量测量 其他 上传书