【问题标题】:Looking for a way to use 'Sortable' function with PHP寻找一种在 PHP 中使用“Sortable”函数的方法
【发布时间】: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)

标签: php jquery jquery-ui


【解决方案1】:

尝试将您的 PHP 代码块替换为

<?php
    $imagesDir = dirname(__FILE__) . '/uploads/gallery1/';
    $images = glob($imagesDir . '*.{jpg,jpeg,png,gif}', GLOB_BRACE);
    for ($i = 0; $i < count($images); $i++) {
?><li><?php
    echo $images[$i];
?></li><?php

请具体说明问题所在 - 如果是错误 - 请在问题中附上消息

【讨论】:

  • 图片无法显示,没有列表。
  • @user2126833 检查 $images 与 var_dump($images);如果是用正确的名称填充
  • var_dump($images) 返回空
  • 所以没有找到文件,也没有找到文件。 “回声 $imagesDir;”看看路径是否正确
  • 手动检查路径后,“uploads”目录与 php 文件共享一个目录,“gallery1”目录位于“uploads”目录中。应该没有问题...
猜你喜欢
  • 2020-03-27
  • 1970-01-01
  • 1970-01-01
  • 2012-02-11
  • 1970-01-01
  • 1970-01-01
  • 2018-07-30
  • 2012-07-05
  • 2011-08-17
相关资源
最近更新 更多