我有几百个pdf,我需要在我的客户网站上单独刊登,我想知道是否有人能指出我需要(或需要写)的代码方向才能做到这是自动的。优选地,代码将能够获取文件夹或zip文件,并从位于文件夹和子文件夹中的pdf生成帖子。它将根据文件夹的名称创建一个类别层次结构,并根据pdf的标题发布标题。每个帖子都会包含指向pdf的链接以及使用Google文档查看器代码的pdf的嵌入版本。这里可以看到一个简短的帖子。如果它也可以自动生成一个很棒的菜单,但它并不重要。那么,有什么想法吗? 另外,这是朋友帮我组装的代码作为开头:
$directory = '/path/to/files/';
$filter = '/*\.pdf$/i'; // Filename ends in .pdf or .PDF
processDirectory($directory, $filter);
function processDirectory($directory, $filter) {
if (substr($directory,strlen($directory)-1,1) != '/') { // Add trailing /
$directory .= '/';
}
if ($handle = opendir($directory)) {
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
if (is_dir($directory.$entry) {
// Recurse into nested directory
processDirectory($directory.$entry, $filter);
} else if (preg_match($filter, $entry)) {
echo "Processing file $directory/$entry<br />\n";
// Valid filename: Build post
// Contents of $post array described in http://codex.wordpress.org/Function_Reference/wp_insert_post
$post = Array(
'post_content' => ' <a href="http://somesite.com/$directory/"' . $entry . '">' . $entry . '</a>.<br />'.
'<iframe src=http://docs.google.com/viewer?embedded=true&url=' .
urlencode($directory.$entry) . '></iframe>',
// This won't be right! You'll need to convert $directory and add your website domain
'post_title' => $entry
);
// Post post
wp_insert_post($post);
}
}
} else {
echo "Failed to open $directory";
}
}
?>