Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ZEND server在PHP中将PDF转换为JPEG_Php_Html_Css_Image_Zend Framework - Fatal编程技术网

使用ZEND server在PHP中将PDF转换为JPEG

使用ZEND server在PHP中将PDF转换为JPEG,php,html,css,image,zend-framework,Php,Html,Css,Image,Zend Framework,我正在使用脚本将PDF转换为JPG Online。但是当我在zend服务器上运行这个脚本并上传任何pdf文件时,文件就会上传到服务器上&它会在浏览器上显示损坏的图像 我使用一个文件夹和一个索引文件来编写代码 上载文件夹 index.php文件 以下是我正在运行的脚本: <html> <head> <style type="text/css"> img {border-width: 0} * {font-family:'

我正在使用脚本将PDF转换为JPG Online。但是当我在zend服务器上运行这个脚本并上传任何pdf文件时,文件就会上传到服务器上&它会在浏览器上显示损坏的图像

我使用一个文件夹和一个索引文件来编写代码

  • 上载文件夹
  • index.php文件
  • 以下是我正在运行的脚本:

        <html>
     <head>
        <style type="text/css">
          img {border-width: 0}
          * {font-family:'Lucida Grande', sans-serif;}
        </style>
     </head>
    <body>
    
    <?php
    $message = "";
    $display = "";
    if($_FILES)
    {
        $output_dir = "uploads/";
        ini_set("display_errors",1);
        if(isset($_FILES["myfile"]))
        {
            $RandomNum   = time();
    
            $ImageName      = str_replace(' ','-',strtolower($_FILES['myfile']['name']));
            $ImageType      = $_FILES['myfile']['type']; //"image/png", image/jpeg etc.
    
            $ImageExt = substr($ImageName, strrpos($ImageName, '.'));
            $ImageExt       = str_replace('.','',$ImageExt);
            if($ImageExt != "pdf")
            {
                $message = "Invalid file format only <b>\"PDF\"</b> allowed.";
            }
            else
            {
                $ImageName      = preg_replace("/\.[^.\s]{3,4}$/", "", $ImageName);
                $NewImageName = $ImageName.'-'.$RandomNum.'.'.$ImageExt;
    
                move_uploaded_file($_FILES["myfile"]["tmp_name"],$output_dir. $NewImageName);
    
                $location   = "/usr/local/bin/convert";
                $name       = $output_dir. $NewImageName;
                $num = count_pages($name);
                $RandomNum   = time();
                $nameto     = $output_dir.$RandomNum.".jpg";
                $convert    = $location . " " . $name . " ".$nameto;
                exec($convert);
                for($i = 0; $i<$num;$i++)
                {
                    $display .= "<img src='$output_dir$RandomNum-$i.jpg' title='Page-$i' /><br>"; 
                }
                $message = "PDF converted to JPEG sucessfully!!";
            }
        }
    }
    function count_pages($pdfname) {
          $pdftext = file_get_contents($pdfname);
          $num = preg_match_all("/\/Page\W/", $pdftext, $dummy);
          return $num;
        }
    $content = $message.'<br />'.$display.'<br><form enctype="multipart/form-data" action="" method="post">
     Please choose a file: <input name="myfile" type="file" /><br />
     <input type="submit" value="Upload" />
     </form>';
    
    
    echo $content;
    ?>
    </body>
    </html>
    
    
    img{边框宽度:0}
    *{字体系列:'Lucida Grande',无衬线;}
    
    断开的图像是:


    根据您的要求在浏览器上查看PDF。 在线试试这个。
    享受它。我希望它能为您充分使用。

    我建议添加一个示例,说明损坏的图像的外观。该图像看起来像此链接的第二幅图像
    禁止您没有权限访问此服务器上的/brandnew/archives/google_breaked_image_00_a_logo.gif。
    @AndriusNaruševičius抱歉链接。现在我把这幅图放到问题上,试着替换
    exec($convert)
    系统($convert.2>&1”)。这应该会显示一条(希望有意义的)错误消息。这是一条很好的评论,但这并不能回答问题。这是一种观点