简体   繁体   中英

delete the images imagejpeg creates

Is it possible to delete the images that imagejpeg creates I have the images uploading to my Amazon S3 server but the files just pop up in the main directory on my server after its ran.

    $new_height = 120;
    $width = imagesx($originalImage);
    $height = imagesy($originalImage);
    $new_width = round(($width * $new_height) / $height);
    $imageResized = imagecreatetruecolor($new_width, $new_height);
    imagecopyresampled($imageResized, $originalImage, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

    $tmp_loc = 'uploads/thumb/';
    $tempfilename = tempnam($tmp_loc, $filename);
    imagejpeg($imageResized, $filename,100);
    imagedestroy($imageResized);
    imagedestroy($originalImage);
    unlink($tempfilename);

I tried imagedestroy and unlink($tempfilename); but the file remains.

You forget to open the variable $tmp_loc .

Look:

$tmp_loc = uploads/thumb/';

Correct:

$tmp_loc = 'uploads/thumb/';

imagejpeg(...)应该输出为$ tempfilename而不是$ filename,那么您将取消链接正确的文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM