Jump to content

help delete image from folder


xcoderx

Recommended Posts

friends i add image to gallery this way

 

$target = "gallery/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;

if (file_exists("gallery/" . $_FILES["uploaded"]["name"]))
      {
echo "<p align=\"center\">";
      echo $_FILES["file"]["name"] . "file name already exists <br/>";
  
}else{

//This is our size condition
if ($uploaded_size > 25600){

echo "Your file is too large. We have a 25kb limit.<br/>";
$ok=0;
}

$types = array('image/jpeg', 'image/gif', 'image/png');

if (in_array($_FILES['uploaded']['type'], $types)) {
// file is okay continue
} else {
$ok=0;
} 


//Here we check that $ok was not set to 0 by an error
if ($ok==0){
echo "<p align=\"center\">";
Echo "Sorry your file was not uploaded.";

}

//If everything is ok we try to upload it
else{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)){
echo "<p align=\"center\">";

$itemurl = $_POST["itemurl"];
  $disc = $_POST["disc"];

   $uid = getuid_sid($sid);
echo "<p align=\"center\">";
  $nopl = mysql_fetch_array(mysql_query("SELECT sex FROM users WHERE id='".$uid."'"));
  if($nopl[0]=='M')
  {
    $usex = "M";
  }else if($nopl[0]=='F'){
    $usex = "F";
  }else{
    $usex = "M";
  }
    
      $res = mysql_query("INSERT INTO gallery SET uid='".$uid."', disc='".$disc."', itemurl='".$target."', sex='".$usex."'");
      if($res)
      {
        echo "User Photo Added<br/>";
      }else{
        echo "Database Error<br/>";
      }

 

and to delete i use this

 


$gid = $_GET["gid"];

  echo "<p align=\"center\">";
  $itemowner = mysql_fetch_array(mysql_query("SELECT uid FROM gallery WHERE id='".$gid."'"));
  if(ismod(getuid_sid($sid))||getuid_sid($sid)==$itemowner[0])
  {
    $res = mysql_query("DELETE FROM gallery WHERE id='".$gid."'");
$res2 = mysql_query("DELETE FROM galcomments WHERE pid='".$gid."'");
$res3 = mysql_query("DELETE FROM rate WHERE pid='".$gid."'");
    if($res||res2||res3)
        {
            echo "Photo Deleted From Gallery<br/>";
        }else{
          echo "Database Error!<br/>";
        }
  }else{
    echo "You can't delete this Photo";
  }
  echo "<br/><br/>";

echo "</body>";

}

 

now the problem is when i click delete link it does delete the photo from db and do not show in gallery but how do i remove it from the folder with the name of the picture?

 

i have no idea how to add ulink option please help

Link to comment
https://forums.phpfreaks.com/topic/157330-help-delete-image-from-folder/
Share on other sites

oh and what im doing is i add the url path of the picture which is being added to the database its not just the name of the picture in particular

 

 

like this $res = mysql_query("INSERT INTO gallery SET uid='".$uid."', disc='".$disc."', itemurl='".$target."', sex='".$usex."'");

where .$target. prints and inserts the picture url like www.site.com/gallery/image.jpg, im not geting idea now how to pull the only name of the picture to delete

something like

 

$res = mysql_query("DELETE FROM fun_gallery WHERE id='".$gid."'");

$res2 = mysql_query("DELETE FROM fun_galcomments WHERE pid='".$gid."'");

$res3 = mysql_query("DELETE FROM fun_prate WHERE pid='".$gid."'");

unlink("gallery" . $itemurl");

 

?? please help me out im not an php expert

That doesn't look right. Watch your quotes. You need to have them paired.

 

I need to know what your variable values are. If $itemurl equals to what the file name is including the file type (jpg, gif) then that is correct, except the extra quote.

 

Please give me an example of what $itemurl will output.

ok itemurl is where the url of the uploaded photo gets stored and it will output the picture in gallery like using http://site.com/gallery/file.jpg    im sure u noticed which uploading the picture i used the $target in adding the url to db  in itemurl now i have no idea in deleting it from the folder at the same time. kindly tell me in simple what all codes do i show you?

 

thanks soo much

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.