Jump to content


murilo

Member Since 22 Mar 2021
Offline Last Active May 09 2021 01:57 AM
-----

Posts I've Made

In Topic: [Solved] Move my account to Tommy

03 May 2021 - 09:30 PM

It's a pleasure to contribute to a great service like HelioHost! :D


In Topic: [Solved] Account suspended

28 April 2021 - 12:55 PM

Well, I'm going to keep the unlink thing in the code since it doesn't return any errors or problems. I don't know if it's necessary to have references to the shared /tmp folder for Imagick to save files on it. Hope it's now cleaning itself.


In Topic: [Solved] Account suspended

28 April 2021 - 12:25 PM

My software is a social network. That code uploads an user image to Cloudinary for being attached to their post. I tried running the script without the unlink line and it didn't create any files in my /tmp folder. Something is wrong. The code doesn't make any references to any other places that it could save temporary files. I'm confused now.


In Topic: [Solved] Account suspended

28 April 2021 - 12:09 PM

Oh, thanks for letting me know about that. I moved the unlink to a line before return and the script still works. Maybe it's cleaning itself now? 


In Topic: [Solved] Account suspended

28 April 2021 - 10:34 AM

I implemented that line in my script and apparently it worked. It looks like this now:

function uploadImage($file, $width = null, $height = null) {
    if($width !== null && $height !== null && extension_loaded('imagick')) {
        $imagick = new Imagick();
        $imagick->setRegistry('temporary-path', '/home/murilo/tmp');
        $imagick->readImageBlob($file);
        if($imagick->getImageFormat() === 'GIF') {
            $imagick = $imagick->coalesceImages();
            $imagick->cropThumbnailImage($width, $height);
            while($imagick->nextImage()) {
                $imagick->cropThumbnailImage($width, $height);
            }
            $imagick = $imagick->deconstructImages();
        } else {
            $imagick->cropThumbnailImage($width, $height);
        }
        $file = $imagick->getImagesBlob();
    }
    if(empty(CLOUDINARY_CLOUDNAME) || empty(CLOUDINARY_UPLOADPRESET)) {
        return null;
    }
    $mime = finfo_buffer(finfo_open(), $file, FILEINFO_MIME_TYPE);
    $ch = curl_init('https://api.cloudinary.com/v1_1/' . urlencode(CLOUDINARY_CLOUDNAME) . '/image/upload');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query(['upload_preset' => CLOUDINARY_UPLOADPRESET, 'file' => 'data:' . $mime . ';base64,' . base64_encode($file)]));
    $response = curl_exec($ch);
    $responseJSON = json_decode($response);
    $responseCode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
    if($responseCode > 299 || $responseCode < 200) {
        return null;
    }
    curl_close($ch);
    return $responseJSON->secure_url;
    unlink ($file, file, $imagick, 'temporary-path');
}