Jump to content

Recommended Posts

<?php

    // connect to the database
    include('connect.php');
    
    // check if the 'id' variable is set in URL, and check that it is valid
    if (isset($_GET['id_slike']) && is_numeric($_GET['id_slike']))
    {
       $id_slike=$_GET['id_slike'];
	$rezultat=mysql_query("SELECT * FROM slike WHERE id_slike=$id_slike ORDER BY id_slike ASC LIMIT 1");
	$redak=mysql_fetch_array($rezultat);
	$myFile=$redak['picture_name'];
	$fh=fopen($myFile, 'w') or die("can't open file");
	fclose($fh);
	unlink("../slike/".$myFile);
	unlink("../slike/thumbnails/".$myFile);
        // delete the entry
      	$result = mysql_query("DELETE FROM slike WHERE id_slike=$id_slike")
        or die(mysql_error()); 
        // redirect back to the view page
        header("Location: index.php");
    }
    else
    // if id isn't set, or isn't valid, redirect back to view page
    {   
        header("Location: index.php");
    }
        
?>

Hail! I found this script on net, add delete form database it and it's work fine. Delete picture, delete thumbnail, and row in database. Script is called brisanje.php. But script creates jpg file called same name as deleted picture but with 0 mb size. Why this does that? Not much problem, more like wonna know why!

Link to comment
https://forums.phpfreaks.com/topic/194429-unlink-let-callit-some-kind-of-trouble/
Share on other sites

$fh=fopen($myFile, 'w') or die("can't open file");
fclose($fh);

 

Since you do not define the directory there that creates an empty file where ever this script is executing from. To fix, remove that (as I do not see that it is doing anything productive) or unlink($myFile); as well. Either or should be fine.

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.