douhang5460 2012-03-21 14:55
浏览 74
已采纳

添加删除照片选项PHP

So basically I have a PHP script that takes all the images from the user's individual folder in the directory and displays them on his/her gallery page. Now I want to add a delete function but im lost as to how to do it. Any help would be great!

<?php
$userid = $_GET['UID'];

$img_path = "./$userid";

chdir($img_path);

$images = glob('*.{jpg, jpeg, png, gif}', GLOB_BRACE);

foreach ($images as $image){
    if (file_exists("./thumbs/$img_path/{image}")){
        echo "<a href='$img_path/{$image}' rel='lightbox'><img src='./thumbs/$img_path/{$image}' alt=\"{$image}\" /></a>";
    } else {
        echo "<a href='$img_path/{$image}' rel='lightbox'><img src='./$img_path/{$image}' width='200' height='150'   alt=\"{$image}\" /></a>";
    }
}
?>
  • 写回答

3条回答 默认 最新

  • doufei0933 2012-03-21 15:03
    关注

    Create an anchor tag in the gallery with the file name as identification attribute. for example.

    <?php
    $userid = $_GET['UID'];
    
    $img_path = "./$userid";
    
    chdir($img_path);
    
    $images = glob('*.{jpg, jpeg, png, gif}', GLOB_BRACE);
    
    foreach ($images as $image){
        if (file_exists("./thumbs/$img_path/{image}")){
            echo "<a href='$img_path/{$image}' rel='lightbox'><img src='./thumbs/$img_path/{$image}' alt=\"{$image}\" /></a>";
            //add this line
            echo "<a href='$img_path/{$image}?delete=$image' rel='lightbox'>Delete</a>";    
        } else {
            echo "<a href='$img_path/{$image}' rel='lightbox'><img src='./$img_path/{$image}' width='200' height='150'   alt=\"{$image}\" /></a>";
        }
    }
    
    //Updated and fixed the error, there was missing closing bracket here.
    if(isset($_GET['delete'])) {
        $image = $_GET['delete'];
        unlink('./thumbs/'.$img_path.'/'.$image);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法