在html中使用PHP来调用文件

时间:2016-01-18 19:12:54

标签: javascript php jquery html

好的,我有一个图片的文件上传按钮,现在当用户上传他们的图片时,它也会在550px到550px的盒子中显示它,以便他们可以查看他们的上传。我需要的是,当他们转到下一页时,他们的图像也会在一个较小的框/缩略图中显示在该页面上。我设法找到这个PHP代码,说它可以回忆起上次上传的图像,但我只是想知道如何将它链接到文件上传按钮,以及如何在较小的框中显示它在下一页..... ?任何建议或解决方案都表示赞赏!(一直试图解决这个问题一周,并决定寻求其他人的帮助)

$path = "/path/to/my/dir"; 

$latest_ctime = 0;
$latest_filename = '';    

$d = dir($path);
while (false !== ($entry = $d->read())) {
  $filepath = "{$path}/{$entry}";
  // could do also other checks than just checking whether the entry is a file
  if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
    $latest_ctime = filectime($filepath);
    $latest_filename = $entry;
  }
}

// now $latest_filename contains the filename of the file that changed last

1 个答案:

答案 0 :(得分:0)

我首先使用move_uploaded_file ( $tmp , $unique_filename )将上传的文件移动/重命名为唯一名称。

然后我会使用php superglobals将唯一的文件名转移到下一页。例如,在上传页面上使用$_SESSION['UPLOADED_FILE'] = $unique_filename,只需在下一页上调用$_SESSION['UPLOADED_FILE']