开发者

Problem with unlink() in php!

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');


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!";


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜