我跟进sitepoint tutorial为我的选项页面创建徽标上传器,但图片上传器无法正常工作。
这里是 functions.php :
class Image(models.Model):
name = models.CharField(max_length=300)
path = models.CharField(max_length=300)
class User(models.Model):
name = models.CharField(max_length=300)
id = models.IntegerField()
images = models.ManyToManyField(Image)
答案 0 :(得分:1)
如果您查看来源,您将会看到enctype未设置为enctype =" multipart / form-data"。您可以执行以下操作来更改enctype
function change_form_enc() {
echo "<script type='text/javascript'>
jQuery(document).ready(function(){
jQuery('form').attr('enctype','multipart/form-data');
});
</script>";
}
if ( is_admin() ) {
add_action('admin_head', 'change_form_enc');
}
答案 1 :(得分:0)
function logo_display()
{
?>
<input type="file" id="logo" name="logo" />
<?php echo get_option('logo'); ?>
<?php
}
function handle_logo_upload()
{
if(!empty($_FILES["logo"]["tmp_name"]))
{
$urls = wp_handle_upload($_FILES["logo"], array('test_form' => FALSE));
if ($urls["error"])
{
return $urls["error"];
}
$temp = $urls["url"];
return $temp;
}
return get_option('logo');
}