Jump to content

Unlink() not deleting file


jbonnett

Recommended Posts

I have chmod'd the file using chmod($img, 0777) on upload and i have also chmod'd vid command prompt and still no joy please help :(


 

$il = explode("/",$_POST['image']);
$img = dirname(__FILE__)."/".$il[0]."/".$il[1]."/".$il[2]."/original/".$il[4]; #/var/www/users/Admin/photos/original/1334.jpg
$img1 = dirname(__FILE__)."/". $il[0]."/".$il[1]."/".$il[2]."/200x200/".$il[4];
$img2 = dirname(__FILE__)."/". $il[0]."/".$il[1]."/".$il[2]."/403x226/".$il[4];
$img3 = dirname(__FILE__)."/". $il[0]."/".$il[1]."/".$il[2]."/460x460/".$il[4];
 
unlink($img);
unlink($img1);
unlink($img2);
unlink($img3);
Link to comment
https://forums.phpfreaks.com/topic/277650-unlink-not-deleting-file/
Share on other sites

I have no error message's and I have tried with @unlink(), also I have tried with and without dirname(__FILE__)."/".

 at the start apart from that the path is good.

 

All I can think of is I use a form of copying the images to different sizes using...

 

 

    function resize($img, $width, $height, $stretch = false)
    {
        $temp = imagecreatetruecolor($width, $height);
        imagealphablending($temp, true);
        imagesavealpha($temp, true);
 
        $bg = imagecolorallocatealpha($temp, 0, 0, 0, 127); // Background color
        imagefill($temp, 0, 0, $bg);
 
        if ($stretch)
        {
            imagecopyresampled($temp, img, 0, 0, 0, 0, $width, $height, imagesx($img), imagesy($img)); 
        }
        else
        {          
            if (imagesx($img) <= $width && imagesy($img) <= $height)
            {
                $fwidth = imagesx($img);
                $fheight = imagesy($img);
            }
            else
            {
                $wscale = $width / imagesx($img);
                $hscale = $height / imagesy($img);
                $scale = min($wscale, $hscale);
                $fwidth = $scale * imagesx($img);
                $fheight = $scale * imagesy($img);
            }
            imagecopyresampled($temp,                             
                $img,                                      
                ($width - $fwidth) / 2, ($height - $fheight) / 2,   
                0, 0,                                              
                $fwidth, $fheight,                                 
                imagesx($img), imagesy($img)               
            );
        }
        return $temp; 
    }
 
$image = imagecreatefromjpeg(dirname(__FILE__)."/users/$session->username/photos/original/".$photo);
$resized = resize($image, 403, 226, false); // false = don't stretch
imagejpeg($resized, dirname(__FILE__)."/users/$session->username/photos/403x226/".$photo, 100);

 

 

 

chmod(dirname(__FILE__)."/users/$session->username/photos/original/".$photo, 0777);
chmod(dirname(__FILE__)."/users/$session->username/photos/200x200/".$photo, 0777);
chmod(dirname(__FILE__)."/users/$session->username/photos/460x460/".$photo, 0777);
chmod(dirname(__FILE__)."/users/$session->username/photos/403x226/".$photo, 0777);

 

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.