【发布时间】:2013-03-06 12:38:14
【问题描述】:
我有一个图像文件夹,我希望用 php 将其加载到可以使用 Sortable jQueryUI 函数移动的图像列表中。我对 php 进行了基本测试,所以我知道 php 没有失败,但我的代码可能由于其他原因而出错,而且我缺乏使用 jQueryUI 的经验。以下是我希望使用的代码的重要部分。
<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script type="text/javascript" src="jquery-ui-1.10.1.custom.min.js"></script>
<script language="javascript" type="text/javascript" defer>
jQuery(document).ready(function( $ ) {
$( "#item-wrap" ).sortable();
$( "#item-wrap" ).disableSelection();
});
</script>
<style>
#item-wrap { list-style-type: none; margin: 0; padding: 0; width: 450px; }
#item-wrap li { margin: 3px 3px 3px 0; padding: 1px; float: left; width: 300px;
height: 300px; font-size: 4em; text-align: center; }
</style>
<ul id="item-wrap">
<?php
$imagesDir = '/uploads/gallery1/';
$images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
$imglist = json_encode($images);
for ($i = 1; $i <= count($imglist); $i++) {
?><li><?php
echo $array[$i];
?></li><?php
}
</ul>
?>
图像无法显示,并且未创建列表。 非常感谢任何帮助或建议。
【问题讨论】:
-
欢迎使用 stackoverflow。您能详细说明实际失败的原因吗?
-
你真的有 /uploads/gallery1/ 文件夹吗?还是您的意思是相对路径,“uploads/gallery1/”?
-
图片未加载,列表未生成。并且响应 Stormherz,路径是相对的。
-
json_encode 转换为字符串,因此
$imglist = json_encode($images);将无法在您的 for 循环中使用count($imglist)。