添加到上传的图像表中可以选择删除其中一个图像 [英] Add to an uploaded images table the choice of deleting one of the images

查看:142
本文介绍了添加到上传的图像表中可以选择删除其中一个图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我可以上传一些图像,查看表格中加载的图像列表。我想添加从服务器删除列表中的一个图像的机会。我试过但是这段代码中的某些东西不起作用。有帮助吗?

I have a page where I can upload some images, see the list of images loaded in a table. I want to add the chance to delete one of the images in the list from the server. I tried but something in this code is not working. Any help?

<html>
<body> 
<form action="" method="post" enctype="multipart/form-data">
    Select a photo to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Load" name="submit">
</form>

<?php 
$dir = 'up/'; 
$files = scandir($dir);
$maxnum = count($files); 
?> 

<table class="thumbnail"> 
<?php $i = 2; 
for ($j = 0; $j < $maxnum; $j++) { 
echo '<tr>'; 
$k = $i + 5; 
for ($i; $i < $k; $i++) { 
If ($i == $maxnum) { break; } 
echo '<td><a href="'.$dir.$files{$i}.'"><img src="'.$dir.$files{$i}.'"></a> </td>';
 if (isset($_GET['delete'])) 
    {
        unlink($_GET['delete']);

        $_SESSION['delete'] = $_GET['delete'];
        unset($_GET['delete']);
        $url = $_SERVER['SCRIPT_NAME'].http_build_query($_GET);
        header("Refresh:0; url=".$url);
    }
?>
   <a href='index.php?delete=up/<?php echo $key?>' id="button">Delete now</a> 
} 
echo "</tr>"; 
} ?> 
</table> 
</div>
</body>
</html>
<?php
if (isset($_POST['submit'])) 
{
echo '<center><h1>succesfully loaded!</h1></center>';
$structure = 'up/';
$target_file = $structure.basename($_FILES["fileToUpload"]["name"]);
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
}
?>    


推荐答案

已完成的错误:


  1. 最后没有关闭循环}}

未在锚标记中提供正确的文件路径 $ dir。$ files {$ i} 。 / p>

Not giving the proper file path $dir.$files{$i} in the anchor tag.

这是评估

以下是代码:

<html>
<body> 
<form action="" method="post" enctype="multipart/form-data">
    Select a photo to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Load" name="submit">
</form>

<?php 
$dir = 'up/'; 
$files = scandir($dir);
$maxnum = count($files); 
?> 

<table class="thumbnail"> 
<?php $i = 2; 
for ($j = 0; $j < $maxnum; $j++) { 
echo '<tr>'; 
$k = $i + 5; 
for ($i; $i < $k; $i++) { 
If ($i == $maxnum) { break; } 
echo '<td><br><a href="'.$dir.$files{$i}.'"><img src="'.$dir.$files{$i}.'" height="50" width="50"></a> </td>';
 if (isset($_GET['delete'])) 
    {
        unlink($_GET['delete']);

        $_SESSION['delete'] = $_GET['delete'];
        unset($_GET['delete']);
        $url = $_SERVER['SCRIPT_NAME'].http_build_query($_GET);
        header("Refresh:0; url=".$url);
    }
?> 
   <a href='index.php?delete=<?php echo $dir.$files{$i}?>' id="button">Delete now</a> 


</table> 
</div>
</body>
</html>
<?php
if (isset($_POST['submit'])) 
{
echo '<center><h1>succesfully loaded!</h1></center>';
$structure = 'up/';
$target_file = $structure.basename($_FILES["fileToUpload"]["name"]);
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file);
}
}}
?>

注意:

第一个锚标记可能会看左对齐。这只是一个设计问题;)

The first anchor tag might look at left aligned. It's just a design issue ;)

这篇关于添加到上传的图像表中可以选择删除其中一个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆