某些pdf文件未上传提取的pdf页面和pdf文件

时间:2013-04-25 11:23:44

标签: php mysql imagemagick wampserver ghostscript

我在下面的脚本中使用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');

            }
                    }
        }

 ?>
                                          

将图书添加到图书馆

                                                                                                                                                                                                                                                           标题                                                                                                                                            作者                                                                                                                                            出版者                                                                                                                                            抽象                                                                                                                                            年                                                                                                                                            类别                                                                        选择...                                   建筑                                   建筑工程                                   土木工程                                   电脑                                   电气工程                                   土地调查                                   综合管理                                   机械工业                                   数量调查                                   其他                                                                                                       上传书籍                                                                                                                                                                                                                                                                                                                                                                                                                                            

1 个答案:

答案 0 :(得分:0)

而不是

$err = "Could not Add to library at this time";

做这样的事情:

$err = "Could not Add to library at this time. SQL: ".$query;

如果您无法查看问题所在,请连接到mysql并运行查询。您应该能够看到mysql错误(我在第一个答案中要求的=)。