HOSTINGER FILE_PUT_CONTENTS HTML2CANVAS : cannot upload the screenshot, but it says that it's not empty

Viewed 70

I already tried validating if the canvas/screenshot worked and it says that it did. I guess the problem is that it isn't uploaded to the directory.

I also already tried enabling the fileUpload option in the Cpanel of the hostinger.

I also tried altering the directory but it still doesnt work, but it works perfectly fine in my localhost.

if($_POST['image'] != null){
    
    $image = $_POST['image'];
    $picpath = $_POST['picpath']; 

    $image_parts = explode(";base64,", $image);

    $image_base64 = base64_decode($image_parts[1]);
    
    $fileLocation = "./public_html/SBAdmin2/includes/customuploads/".$picpath;
    file_put_contents($fileLocation, $image_base64);


}
1 Answers

Try something like:

    // ...

    $fileLocation = __DIR__ . '/public_html/SBAdmin2/includes/customuploads/' . $picpath;
    file_put_contents($fileLocation, $image_base64);
}

Note that "./" refers to current-directory, which may not be what you expect, and on servers it may refer to another directory.

Related