所以我想要的是在下载通过 wordPress-plugin 高级自定义字段动态上传的文件时请求密码。我无法让它工作,这是我的代码:
html:
<div class="documentWrap">
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'content', 'page'); ?>
<?php if(get_field('dokumentgrupp')): ?>
<?php while(has_sub_field('dokumentgrupp')): ?>
<div class="docGroup clearfix">
<h2><?php the_sub_field('gruppnamn'); ?></h2>
<?php if(get_sub_field('filer')): ?>
<?php while(has_sub_field('filer')): ?>
<ul>
<li>
<h3><?php the_sub_field('filnamn'); ?></h3>
<a href="<?php the_sub_field('fil_url'); ?>">ladda ner</a>
<!div id="passWrap">
<div id="passBox">
<?php // if( get_field('password') ): ?>
<form method="post">
<input name="pass" type="password" action="download_pw.php">
<input type="submit" name="submit" value="ladda ner">
</form>
</div>
<?php //endif; ?>
</div>
</li>
</ul>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
<?php endwhile; ?>
</div>
下载_pw.php:
<?php
$pw = md5($_POST['pass']);
$valid_pw = md5(get_sub_field('password'););
$file_url = get_sub_field("fil_url");
if {$pw != $valid_pw) {
echo 'Tyvärr har du inte tillgång till denna fil';
}else{
header('Location: $file_url');
}
?>