Php 如何使用jquery从文件夹中提取图像?
我在Php 如何使用jquery从文件夹中提取图像?,php,jquery,Php,Jquery,我在index.php <?php $filepath ="images/topbanner"; $files =scandir($filepath); if ($handle = opendir($filepath)) { echo '<div>'; while (false !== ($entry = readdir($handle))) { if($entry != '.' &&a
index.php
<?php
$filepath ="images/topbanner";
$files =scandir($filepath);
if ($handle = opendir($filepath)) {
echo '<div>';
while (false !== ($entry = readdir($handle))) {
if($entry != '.' && $entry != '..'){
?>
<img src="<?=$filepath.'/'.$entry?>" />
<?php
}
}
echo '<div>';
closedir($handle);
}
?>
" />
但是我想知道我可以用jquery从文件夹中提取图像吗
如果jquery无法实现:我如何才能将此代码嵌入js文件中的slider.js
,而不是index.php
。“我想知道,我可以用jquery从文件夹中提取图像吗?”
在浏览器中运行的JavaScript没有
访问本地或基于服务器的文件系统
为此,您需要使用PHP
也许您可以将一个URL数组从PHP传递到JS/jQuery。您应该使用
AJAX、PHP和jQuery
。这将完成您的任务
单独使用jQuery或Javascript无法处理服务器目录(文件夹),因为它们只能在客户端浏览器上工作
- 使用jquery/Javascript进行用户交互
- 允许AJAX作为中间件对服务器进行新的
HTTP服务器调用
index.php
<?php
$filepath ="images/topbanner";
$files =scandir($filepath);
if ($handle = opendir($filepath)) {
echo '<div>';
while (false !== ($entry = readdir($handle))) {
if($entry != '.' && $entry != '..'){
?>
<img src="<?=$filepath.'/'.$entry?>" />
<?php
}
}
echo '<div>';
closedir($handle);
}
?>
(AJAX与客户端浏览器和服务器进行动态交互)有文件API,但并非所有浏览器都完全支持该API。您是否有可能构建一个web服务来枚举文件夹中的所有文件?这是一个常见选项。您应使用AJAX、PHP和jQuery。这将完成您的任务