tags:

views:

81

answers:

2

I'm creating a temp image always named 1.png under specific folder and once i read the image_contents and process, i use unlink() to delete that specific image from that folder.

But sometimes the image file is not deleted and the same image is file is read and processed.

That script is working otherwise fine...

There is no permission related issues , as the files are deleted sometimes...

Will there be any issue when the script is repeatedly called and the image with the name is already present and not deleted etc.. ???

Please suggest me what would be the problem

      extension_loaded('ffmpeg');
      $max_width  = 120;
      $max_height = 72;
        $path ="/home/fff99/public_html/temp/";
            .....
            .....
        $nname = "/home/friend99/public_html/temp/".$imgname;
        $fileo = fopen($nname,"rb");
        if($fileo)
        {
            $imgData = addslashes(file_get_contents($nname));
                    ....
                    ...
                    ..
        }
        unlink('$nname');
+1  A: 

You should check the return value from unlink to see if it's returning false. Most likely the problem is an open file handle preventing unlink from completing; your fopen should have a corresponding fclose:

fclose($fileo);
if(!unlink($nname))
    echo "AAAAH!";
Michael Mrozek
thats fine. I should look after adding a fclose() . And i have one doubt. My script will be called for every upload the user does on my website. So will that be a bother to create a file always named '1.png' , if so then how to handle this..
kvijayhari
A: 

I had a similar problem using @unlink it would pick and choose when to delete, so I switched to this;

if (file_exists($filename)) {
unlink($filename);
}

for some reason that worked for me, hope it helps.

Jamie
That doesn't seem like it would help with unlink leaving a file behind, it just prevents trying to unlink a file that doesn't exist
Michael Mrozek
well i was just about to reply with a 'but unlinking without out an fclose results in a permission error' which he said he wasnt getting then i saw; unlink('$nname'); which should not have been in single quotes. Then he would have an error and now it all makes sense.
Jamie