当用户上载新图像时,先前图像从laravel文件夹中删除

时间:2018-09-22 12:08:12

标签: php laravel image

当用户上传新图像时,我想删除文件夹中的上一张图像,我使用Laravel ....我尝试做一些事情,但对我没有任何想法吗?

  func main() {
        outChan := make(chan []byte)

        fmt.Printf("Please input URL")
        fmt.Scanln(&url)
        wg.Add(1)
        go nikto(outChan)
        wg.Add(1)
        go whois(outChan) 
        wg.Add(1)
        go nmap(outChan) //you are just missing the argument here.
        for i := 0; i < 3; i++ {
            bs := <-outChan
            fmt.Println(string(bs))
        }

        close(outChan)
        wg.Wait()
    }

$user = User::find(Auth::user()->id);
File::delete($user->pic);

3 个答案:

答案 0 :(得分:0)

使用php的unlink功能

unlink($file_path);

要创建路径:

$file_path = base_path().'/images/post/'.$post->photo;

答案 1 :(得分:0)

$idname = User::where('user_id', $request->userid)->update([
    'users_profile_name' => $usersName
]);
File::delete('/public/uploads/users/".$request->userid."');

$file=$request->file('users_profile_name');
$file->move(base_path('/public/uploads/users'),$usersName);

答案 2 :(得分:0)

您可以使用unlink()函数来实现。这是我的项目中的代码,如果用户要添加其他图片,它会删除上一张图片:

$usersImage = public_path("/images/{$user->photo->path}"); //Finding users previous picture
        if(file_exists($usersImage)){ //If it exits, delete it from folder
            unlink($usersImage);
        }

之后,您只需添加添加另一张图片的逻辑

相关问题