将取消链接限制为仅一个


Limit unlink to one only

Aloha,我有一个下载按钮,当下载图像时,它使用会话(路径)进行分配。 然后我删除了之前使用的图片,但是当图像名称相同时,"取消链接($_SESSION['图片']);"会删除它们 - 我想每次删除一个......像这样的东西"取消链接($_SESSION['图片'] <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;

我们已经说过了。从上传文件开始

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

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