0

i have got a very crazy! problem

i am trying to erase an image from e web page

iwrote this piece of code to show the image and the bullet for the uset to delete

$dir2='../../random/images2/';

$files1 = scandir($dir2);

foreach ($files1 as $value)
{
    if ((substr($value, -3)==="jpg") or (substr($value, -3)==="JPG") or (substr($value, -3)==="gif") or (substr($value, -3)==="GIF") or (substr($value, -3)==="png") or (substr($value, -3)==="PNG"))
    {
        ?>
     <img src="../../random/images2/<?php echo $value;?>"  width="200" height="150" alt="some_text">
      <?php
       echo "
            <form action='delete.php' method='post'>
           <input type='hidden' name='Name2' value='$value'>
           <input type='hidden' name='absolute_path' value='$absolute_path'>
           <input type='submit' value='Delete'>
            </form>

";
    } 

the delete.php

$Name2=$_POST['Name2'];

if ($Name2)
{
echo "in 2<br>";
   $PathFIle='../../random/images2/'.$Name2;
     $PathFIle = strval (trim($PathFIle));
   echo $PathFIle;
   echo "<br>";
   if (file_exists('$PathFIle'))
   {
    unlink($PathFile);
   }
}

the message i get is that file doesnt exists. The file surely exists. note that i ve taken the echo result of my browser and i replaced the code like that

 if (file_exists('../../random/images2/apagk.jpg'))
   {
    unlink('../../random/images2/apagk.jpg');
   }

and it worked perfectly.....

what is going on the $PathFIle contains the '../../random/images2/apagk.jpg' butthe file exists and thw unlink doesnt recornize it...

any ideas???

Edited by dourvas

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by pritaeas
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.