在 html 中使用 PHP 来调用文件


Using PHP in html to call a file through

好的,所以我有一个用于图像的文件上传按钮,现在当用户上传他们的图像时,它也会在 550px x 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

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

然后,我将使用 php 超全局变量将唯一的文件名带到下一页。例如,在上传页面上使用$_SESSION['UPLOADED_FILE'] = $unique_filename,并在下一个页面上简单地调用$_SESSION['UPLOADED_FILE']