Chi*_*dan 6 wordpress uploader
我正在尝试实现一个首页Wordpress上传器,它允许用户从Wordpress页面上传图像,并在上传之前调整图像大小.我找到了Agile Uploader.上传者的形式.
问题是当我单击表单中的提交按钮发送数据时,所有字段都存储在一个帖子中,但图像没有.
以下是我上传页面的代码:
<form id="submitForm" action="<?php echo get_permalink(); ?>" method="post" enctype="multipart/form-data" onsubmit="return ray.ajax()">
<!-- upload photos -->
<div style="float:left;width:410px; height:246px;">
<div id="multiple"></div>
</div>
<script type="text/javascript">
jQuery('#multiple').agileUploader({
formId: 'submitForm',
flashVars: {
file_post_var: 'attachment',
firebug: false,
form_action: '',
file_limit: 15,
max_post_size: (1000 * 1024)
}
});
</script>
</div> <!-- end - upload photos -->
</form>
Run Code Online (Sandbox Code Playgroud)
和Wordpress上传的代码(它在同一个文件中)
/* upload photos */
if ($post_error == false) {
/* required files */
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
$files = $_FILES['attachment'];
if ($files) {
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
}
$_FILES = array("attachment" => $file);
//$_FILES = array_reverse($_FILES);
foreach ($_FILES as $file => $array) {
$attach_id = media_handle_upload( $file, $ad_id, array(), array( 'test_form' => false ) );
if ($attach_id < 0) { $post_error = true;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
小智 0
您确定图像没有保存为创建的帖子的“附件”吗?
尝试运行:
$attachments = get_posts( array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post->ID,
'exclude' => get_post_thumbnail_id())
);
var_dump($attachments);
Run Code Online (Sandbox Code Playgroud)
在您用来查看帖子的模板文件中。如果您不熟悉编码,您可以使用插件来显示附加文件。就像这个“列表附件简码”插件一样。
| 归档时间: |
|
| 查看次数: |
367 次 |
| 最近记录: |