我想實現一個首頁的WordPress的上傳,它可以讓用戶從Wordpress頁面上傳圖片的可能性,並在上傳前調整圖片大小。我找到了Agile Uploader。上傳者是一種形式。敏捷上傳Wordpress的實施
問題是,當我點擊表單中的提交按鈕發送數據時,所有字段都存儲在一個帖子中,但圖像沒有。
這裏是我的上傳頁面的代碼:
<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>
和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;
}
}
}
}
我在做什麼錯?
所以問題是保存整個表單? – janw
是的,這是問題 –
任何錯誤消息?,檢查您的螢火蟲控制檯和張貼到這裏得到快速回答 –