Imgur

BETAALD
Verified
Door Imgur | Bijgewerkt 24 days ago | Entertainment
Populariteit

9.9 / 10

Latency

1,136ms

Serviceniveau

100%

Health Check

N/A

Terug naar alle discussies

uploading using php, always says image corrupted or not format not supported

Rapid account: Abanoub Nassem
AbanoubNassem
9 years ago

if (isset($_POST[‘upload’], $_FILES[‘file’])) {
require_once ‘vendor/autoload.php’;

        global $Pointer;

        $valid_file_extensions = array(".jpg", ".jpeg", ".gif", ".png");

        $file_extension = strrchr($_FILES["file"]["name"], ".");

        if (in_array($file_extension, $valid_file_extensions)) {
            if (@getimagesize($_FILES["file"]["tmp_name"]) !== false) {

                $filename = $_FILES['file']['tmp_name'];
                $handle = fopen($filename, "r");
                $data = fread($handle, filesize($filename));

                $response = Unirest\Request::post("https://imgur-apiv3.p.mashape.com/3/image",
                    array(
                        "X-Mashape-Key" => "key",
                        "Authorization" => "Client-ID ID",
                        "Content-Type" => "application/x-www-form-urlencoded"
                    ),
                    array(
                        "image" => base64_encode($data)
                    )
                );

                var_dump(base64_encode($data));
                $result = json_decode($response->raw_body);

                if ($result->success) {
                    var_dump($result);
                } else {
                    $Pointer->Bootstrap()->Alert($result->data->error, "danger");
                }

            }
        }
    }

Doe mee aan de discussie - voeg hieronder een opmerking toe

Log in / Schrij u in om nieuwe opmerkingen te plaatsen