当我尝试访问我的本地网站时,在上传新主题后,我收到消息: 解析错误:语法错误,意外'}'在第52行的C:\ wamp \ www \ test03 \ wp-content \ themes \ hazera \ inc \ all-to-pdf.php
这是代码:
<? function to_pdf_form(){ ?>
<form method="post" action="">
<input style="margin-top:20px;" class="button" type="submit" name="submit-all-to-pdf" value="Upload all products to PDF!">
</form>
<p>Files uploaded to /wp-content/uploads/products-pdf.</p>
<?php
if ( isset($_POST['submit-all-to-pdf']) ){
ini_set('max_execution_time', 300);
global $post;
$args = array( 'post_type' => 'product', 'posts_per_page' => -1 );
$the_product = get_posts( $args );
foreach( $the_product as $post ) {
$product_id = get_the_ID();
$product_name = get_the_title ( $product_id );
if(class_exists('Pdfcrowd')){
if ( !$product_id ) die();
$pdf_version_url = add_query_arg( array('pdf_version' => 1), get_permalink($product_id));
$wp_upload_dir = wp_upload_dir();
if (!file_exists($wp_upload_dir['basedir'] . '/products-pdf')) {
mkdir($wp_upload_dir['basedir'] . '/products-pdf', 0777, true);
}
$pdf_file_name = 'product-' . $product_id . '.pdf';
$pdf_file_path = $wp_upload_dir['basedir'] . '/products-pdf/' . $pdf_file_name;
try
{
// create an API client instance
$client = new Pdfcrowd("username", "password");
if ( file_exists( $pdf_file_path ) ) continue;
$out_file = fopen($pdf_file_path, "wb");
$client->setHtmlZoom("120");
$client->convertURI($pdf_version_url, $out_file);
fclose($out_file);
// send the generated PDF
echo '<strong>' . $product_name .' uploaded successfully. </strong><br/>';
}
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why . "<br/>";
}
}
}
}
}
?>
我不明白这里有什么不对。
谢谢
答案 0 :(得分:0)
编辑:
你正在使用这样的短开标签:
<? function to_pdf_form(){ ?>
更改为
<?php function to_pdf_form(){ ?>
你不应该有任何问题。
这是错的,忽略它:
此处有一个额外的结束}
,将其删除
catch(PdfcrowdException $why)
{
echo "Pdfcrowd Error: " . $why . "<br/>";
}
//}