Php 显示响应状态-使用JQuery上载图像
我想做的是从URL下载一些图片,然后上传到WordPress post,我的表格如下:Php 显示响应状态-使用JQuery上载图像,php,jquery,wordpress,Php,Jquery,Wordpress,我想做的是从URL下载一些图片,然后上传到WordPress post,我的表格如下: <form method="post" id="upload"> <?php foreach($data as $row): ?> <label>File Name</label> <input type="text" id="filename_<?php echo $row->id;?>" name="data[<?php ec
<form method="post" id="upload">
<?php foreach($data as $row): ?>
<label>File Name</label>
<input type="text" id="filename_<?php echo $row->id;?>" name="data[<?php echo $row->id;?>][filename]" value="<?php echo $file_name;?>" />
<label>Title</label>
<input type="text" id="title_<?php echo $row->id;?>" name="data[<?php echo $row->id;?>][title]" value="<?php echo $title;?>" />
<?php endforeach;?>
<button name="act" value="savepost">Save</button>
</form>
<!-- showing result here -->
<div id="result"></div>
如何使用jquery在单击保存按钮时显示响应结果。将您的img附加到html 像
$($post).each(函数(){
$(“#您想要显示的位置ID”)。附加(“”)
})
将您的img附加到html
像
$($post).each(函数(){
$(“#您想要显示的位置ID”)。附加(“”)
})
确保表单具有enctype=“多部分/表单数据”属性
$new_post = wp_insert_post($post_array);
if (!function_exists('wp_generate_attachment_metadata')){
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload( $file, $new_post );
}
}
if ($attach_id > 0){
update_post_meta($new_post,'_thumbnail_id',$attach_id);
}
确保表单具有enctype=“multipart/form data”属性
$new_post = wp_insert_post($post_array);
if (!function_exists('wp_generate_attachment_metadata')){
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload( $file, $new_post );
}
}
if ($attach_id > 0){
update_post_meta($new_post,'_thumbnail_id',$attach_id);
}
$\u POST
没有文件数据。很明显,$\u文件
$\u帖子
没有文件数据。它是$\u文件
。
$new_post = wp_insert_post($post_array);
if (!function_exists('wp_generate_attachment_metadata')){
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
}
if ($_FILES) {
foreach ($_FILES as $file => $array) {
if ($_FILES[$file]['error'] !== UPLOAD_ERR_OK) {
return "upload error : " . $_FILES[$file]['error'];
}
$attach_id = media_handle_upload( $file, $new_post );
}
}
if ($attach_id > 0){
update_post_meta($new_post,'_thumbnail_id',$attach_id);
}