gpt4 book ai didi

php - 在新标签页中打开随机图片 PHP

转载 作者:太空宇宙 更新时间:2023-11-04 04:37:53 25 4
gpt4 key购买 nike

我制作了一个 php 行,从某个目录中随机生成一张图片:

<?php

function random_pic($dir = 'pics')
{
$files = glob($dir . '/*.*');
$file = array_rand($files);
return $files[$file];
}

?>

现在我不知道如何让随机文件在新选项卡中打开..我尝试使用的代码如下:

<a href="" title="Click to open in new page!!">
<img src=""<?php echo random_pic(); ?>" alt="" height="400" width="450" border="0"/>
</a>

我想这样做,当您单击图片时,它会在新选项卡中打开(或在同一页面上但无需重新加载),

谢谢! :)

最佳答案

<?php $random_pic = random_pic(); ?>
<a href="<?php echo $random_pic; ?>" target="_blank" title="Click to open in new page!!"><img src="<?php echo $random_pic; ?>" alt="" height="400" width="450" border="0"/></a>

关于php - 在新标签页中打开随机图片 PHP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15986595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com