dou7851 2014-12-02 08:08
浏览 46

限制取消链接仅限一个

Aloha, I have a download button and when the image is downloaded it`s dispalyed using session (path). I then delete the picture that was used before, but when the name of the image is the same, "unlink($_SESSION['picture']);" deletes both of them- I want to delete ony one each time... Something like this "unlink($_SESSION['picture'] < 1);" which doesn't work. Please Help:), Aloha

And here's the code which saves the picture..

session_start();

$filename    = $_FILES["picture"]["tmp_name"];
$destination = "upload/" . $_FILES["picture"]["name"]; 
move_uploaded_file($filename, $destination); //save uploaded picture in your directory
$_SESSION['picture'] = $destination;
  • 写回答

1条回答 默认 最新

  • douqiao1997 2014-12-02 08:35
    关注

    Has we've said. Start with uploading the file

    session_start();
    
    $filename    = $_FILES["picture"]["tmp_name"];
    //Cutted the file name from the $destination
    $destination = "upload/"; 
    
    //Insert Into DB the info.
    //Query Similar To
    $sql = "INSERT INTO mytable (filename) VALUES (".$filename.")";
    
    //Get from DB the ID generated.
    $sql2 = "SELECT id FROM mytable WHERE filename = '".$filename."'";
    //Fetch the data into a $filenameNew var
    
    move_uploaded_file($filename, $destination.$filenameNew); //save uploaded picture in your directory with the db id
    
    $_SESSION['picture'] = $destination.$filenameNew;
    

    On delete instead

     $sql2 = "SELECT id FROM mytable WHERE ..."; //Get the id name of the file
    //put id on a var - $toUnlink
    unlink($toUnlink);
    
    $sqlDelete = "DELETE FROM mytable WHERE id = '".$toUnlink."'";
    

    This is a working chain. You need to some work to make it works correctly based on your application.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统