Jump to content

delete image


Marcos01

Recommended Posts

Hi all,

 

I use 2 dropdown boxes to select the image I want to delete. First select directory and then select the image. The path to the image: ../userfiles/images/projects/

 

How do I use the path in the code?

 

This is the code so far:

 

//delete image:

 

$folder = $_POST["folder"];

$image = $_POST["images"];

 

//delete image

if ($_POST['doaction']=='submit'.'delete')

{

unlink($folder.$image);

}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/122021-delete-image/
Share on other sites

That's not really the best method... what if someone passes ../../../ for the dir and index.php for the image? There goes your homepage. I would strip all of the .. and / from both inputs. After you've done that..

 

unlink("../userfiles/images/projects/$folder/$image");

 

should suffice.

Link to comment
https://forums.phpfreaks.com/topic/122021-delete-image/#findComment-629858
Share on other sites

Example for delete a file..........

 

This will work so be very carefull remeber, once a file is deleted

it gon for good!.

 


<?php

   chdir('../pics/'); //cheek the directory there.........
    $do = unlink($fileToDel); // delete the file from the cheeked directory......
    if($do=="1"){ // if do ==1 then echo file was deleted.........
        echo "The file was deleted successfully.";
    } else { echo "There was an error trying to delete the file."; }// if file not there then echo message
?>

Link to comment
https://forums.phpfreaks.com/topic/122021-delete-image/#findComment-629865
Share on other sites

Thanks for the replies. Unfortunately it didn't work.

I tried this code first code:

$folder = $_POST["folders"];
$image = $_POST["images"];

if ($_POST['doaction']=='submit'.'delete') 
  { 
unlink("../userfiles/images/projecten/$folder/$image");
  }

 

Next I will try your code redarrow

Link to comment
https://forums.phpfreaks.com/topic/122021-delete-image/#findComment-629869
Share on other sites

Tried this code too but didn't work. I am not getting any errors.

$folder = $_POST["folders"];
$image = $_POST["images"];
$path = "../userfiles/images/projecten/";

if ($_POST['doaction']=='bevestigen'.'wissen') 
{ 

  chdir('../userfiles/images/projecten/'.$folder.'/'); 
    $do = unlink($image); 
    if($do=="1"){ 
        echo "The file was deleted successfully.";
    } else { echo "There was an error trying to delete the file."; }
}

Link to comment
https://forums.phpfreaks.com/topic/122021-delete-image/#findComment-629889
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.