删除上传目录中的文件

时间:2019-02-22 15:56:13

标签: php

我有一个图像文件上传存储库:uploads

public function addArticle($formData,$files) {
    $articles = $this->articleDao->findAll();
    $events = $this->eventDao->findEvents();

    $file = $files->get('image');
    $target_dir = "public/uploads/";
    $extensions = [  
         'image/jpeg'=>'.jpg',
         'image/png'=>'.png'
      ];
    $imageName = uniqid().$extensions[$file['type']];
    move_uploaded_file($file["tmp_name"], $target_dir.$imageName);

    $this->articleDao->insert($formData->get("id"),$formData->get("title"),$formData->get("content"),'/public/uploads/'.$imageName,$formData->get("legend"));

    header('location: /admin');
    die();
}

并且我想在删除文章时删除图像:

public function supprimArticle($id) {
    $supprim = $this->articleDao->delete($id);

    unlink(....);

    header('location: /admin');
    die();
}

但是我不知道在unlink()中放入什么。

0 个答案:

没有答案