限制取消链接仅限一个

时间:2014-12-02 08:08:32

标签: php

Aloha,我有一个下载按钮,当下载图像时,它会使用会话(路径)显示出来。然后我删除之前使用的图片,但是当图片的名称相同时,“取消链接($ _ SESSION ['picture']);”删除它们 - 我想每次删除一个......这样的东西“unlink($ _ SESSION ['picture']< 1);”这不起作用。 请帮忙:),阿罗哈

这是保存图片的代码..

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 个答案:

答案 0 :(得分:0)

我们已经说过了。 首先上传文件

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;

改为删除

 $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."'";

这是一个工作链。您需要做一些工作才能使其根据您的应用程序正常工作。