Jump to content

"unlink" let callit some kind of trouble.


regoch

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.

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.