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
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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.