Reputation: 63
Is it possible in PHP to update a profile picture and delete the current one from the folder and its link from the database?
If yes, please help: I managed to delete the link from the database but the picture in the folder remains.
Upvotes: 0
Views: 3762
Reputation: 2817
Let’s assume that you have a folder called Images where you uploaded your pictures So in that folder there is an image called test.jpg . this code will delete that image in the folder . @David Rabinowitz thanks for giving him a great answer which uses a database but I am also trying to give him a second example which does not use a database maybe it will also help him
<?php
$file ="test.jpg";
$filedel="images/".$file;
if(file_exists($file)){
echo "file exits";
unlink($filedel);
else{
echo "the file you want to delete does nto exist ";
}
?>
Upvotes: 0
Reputation: 684
PHP unlink
function is used to del the existing file from directory
$filename = 'define file name here with proper path';
unlink($filename);
Upvotes: 0
Reputation: 5399
Use the unlink function.
//before deleting the path from database, get it in one variable using php
$filename = path from database;
unlink($filename);
Upvotes: 4