从目录和会话变量问题检索图像 - php

BIW*_*BIW 3 html javascript php jquery canvas

从我服务器上的目录中检索图像时出现问题,所以主要序列是:在页面中(multiupload.php)我添加了输入,允许预览图像,当用户提交时,新目录将创建其会话ID,然后将图像存储在唯一目录中,然后将页面定向到(drag.php).新加载的页面有一个带有不同div的画布,用于控制附加到该画布的过滤器.我的问题在于将指定的s_id作为目录名从一个页面检索到另一个页面.

问:我是否正确检索会话变量?或适当使用它们?

这是multiupload.php上传脚本的必要代码片段.

<?php
  $dir_id = session_id(md5(uniqid()));
  session_start($dir_id);
  $path = "uploads/";
  $dir = $path.$dir_id;
  $path = $path.$dir_id."/";
  if (file_exists($dir)) {
    system('/bin/rm -rf ' . escapeshellarg($dir));
  } else {
    mkdir($path);
    chmod($path, 0722);  
  }
  $_SESSION["id"] = $dir_id;
  $_SESSION["directory"] = "/" . $dir;
  $_SESSION["path_name"] = $path;
?>
Run Code Online (Sandbox Code Playgroud)

我定义目录,整个路径和目录的ID.我想在下一页中检索id,但它没有正确执行.

这是来自drag.php的检索代码

$realPath = 'uploads/'. echo $_SESSION['id'];

$handle = opendir(dirname(realpath(__FILE__)).$realPath;
while($file = readdir($handle)){
    if($file !== '.' && $file !== '..'){
        echo '<img src="uploads/'.$file.'" border="0" />';
    }
}
Run Code Online (Sandbox Code Playgroud)

我的最终结果是我希望在页面上绘制所有图像.现在我希望它们可以在任何地方被绘制,只要它们可见.

如果我的问题不明确,请随时编辑或评论我应该改变的地方.如果您需要更多代码或信息,请告诉我们.

小智 6

请将您的代码修改为以下代码:

<?php
  $dir=$_SESSION['id'];
  $realPath = '/uploads/'.$dir;
  $handle = opendir(dirname(realpath(__FILE__)).$realPath);
    while($file = readdir($handle)){
      if($file !== '.' && $file !== '..'){
        echo '<img src="'.$realPath.'/'.$file.'" border="0" width="200" />';
    }
  }
?>
Run Code Online (Sandbox Code Playgroud)

我使用这个代码,我得到这样的o/p:

在此输入图像描述