我想使用wordpress上传多张图片。
以下是我用于单次上传的代码
if ( ! function_exists( 'wp_handle_upload' ) )
require_once( ABSPATH . 'wp-admin/includes/file.php' );
$uploadedfile = $_FILES['photo'];
$upload_overrides = array( 'test_form' => FALSE );
$movefile = wp_handle_upload( $uploadedfile, $upload_overrides );
if ( $movefile ) {
echo "File is valid, and was successfully uploaded.\n";
var_dump( $movefile);
}
else {
echo "Possible file upload attack!\n";
}
如何使用wordpress上传多张图片?
答案 0 :(得分:2)
尝试这样实现:
s = "<html><head><title>Current IP Check</title></head><body>Current IP Address: 165.91.15.131</body></html>"
info = re.findall(r'[\d.-]+', s)
答案 1 :(得分:1)
通过使用原生WordPress Media Uploader,您可以更轻松地实现您的目标。
我有一个很好的资源书签在某一点,但似乎无法找到它。几个月前我遇到了一个需要同样事情的情况。这就是我最终做的事情:
将WordPress图像脚本加载到我的PHP脚本的开头:
jQuery(document).ready(function($) {
// Define a variable to be used to store the frame data
var file_frame;
var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
var set_to_post_id = 999; // Set this
$('#upload_button').live('click', function( event ){
element = $(this);
event.preventDefault();
// If the media frame already exists, reopen it.
if (file_frame) {
// Set the post ID to what we want
file_frame.uploader.uploader.param('post_id', set_to_post_id);
// Open frame
file_frame.open();
return;
} else {
// Set the wp.media post id so the uploader grabs the ID we want when initialised
wp.media.model.settings.post.id = set_to_post_id;
}
// Create the media frame.
file_frame = wp.media.frames.file_frame = wp.media({
title: $(this).data('uploader_title'),
button: {
text: $(this).data('uploader_button_text'),
},
multiple: true // Set to false to allow only one file to be selected
});
// When an image(s) have been selected, run a callback.
file_frame.on('select', function() {
// Do something if necessary
function_to_fire();
});
// Finally, open the modal
file_frame.open();
});
});
然后你可以使用jQuery在元素点击上调用上传器,如下所示:
attachment
传递给回调函数的set_to_post_id
对象将包含所有ID以及上传的附件。
var test = 0; // initial value
var checkInterval = 1000; // time in millisecond, 1000 = 1 second
setInterval(function() {
if(test !== 0) { // check if test is not equal to initial value
console.log("Test value changed! New value: "+test);
}
}, checkInterval);
是您想要“附加”媒体的帖子/页面的ID。如果您不想将它们附加到帖子上,则不必担心这一点,上述代码中的某些代码将不适用。