0

嗨,您的帖子没有太多解释代码部分的上下文,请更清楚地解释您的场景。我花了繁琐的时间,警告问一个问题

我收到以下错误,如果您能提供帮助,我将不胜感激谢谢

imgur.php图片上传脚本

<?php
    $current_api_key = "api key";
    ?>

    <html>
    <body>
    <style type="text/css">
    body { font-family: Verdana, Geneva, sans-serif; font-size:12px; color:#000; background:#f9f9f9; margin:0px; padding:0px; }
    a { color:#21759b }
    a:hover { color:#d54e21; }
    h1 { font-size: 18px; font-weight: bold; }
    h2 { font-size: 14px; font-weight: bold; }
    #media-upload-header ul { margin-left:21px; margin-top:11px; margin-bottom:8px; padding:0px; }
#media-upload-header li { display:inline; margin-right:8px; }
#media-upload-header a { text-decoration:none; }
    #content { background:#FFF; border-top:#dfdfdf solid 1px; border-bottom:#dfdfdf solid 1px; padding:25px; }
.current { color:#d54e21; background-color:#FFF; padding:5px 10px 10px 10px; border-top:#dfdfdf solid 1px; border-left:#dfdfdf solid 1px; border-right:#dfdfdf solid 1px; }
</style>

    <div id="content" align="center">
    <h1>Choose image to upload :</h1>
    <form enctype="multipart/form-data" action="<?php echo $plugin_path; ?>api.php?api=<?php echo $current_api_key; ?>" method="POST">
    <input name="userfile" type="file" /><br /><br />
    <input type="submit" value="Upload to imgur.com" />
    </form>
    </div>

</body>
</html>

api.php其他脚本

    <html>
<head>
<style>
body { font-family: Verdana, Geneva, sans-serif; background-color: #FFF; }
h1 { font-size: 14px; font-weight: bold; color: #000; }
a { color:#000; }
#insert_box_img { float:left; width:200px; }
#insert_box_button { float:left; width:400px; }
</style>

</head>
<body>

<?
    $api_key = "api key";
    $file = getcwd() . '/' . basename( $_FILES['userfile']['name']);
    move_uploaded_file($_FILES['userfile']['tmp_name'], $file);
    list($width, $height, $file_type) = getimagesize($file);

    if ($file_type == 3) {
        $image = imagecreatefrompng($file);
        imagealphablending($image, false);
        imagesavealpha($image, true);
        ob_start();
        imagepng($image);
        $data =  ob_get_contents();
        ob_end_clean();
    }

    if ($file_type == 2) {
        $image = imagecreatefromjpeg($file);
        imagealphablending($image, false);
        imagesavealpha($image, true);
        ob_start();
        imagejpeg($image);
        $data =  ob_get_contents();
        ob_end_clean();
    }

    if ($file_type == 1) {
        $image = imagecreatefromgif($file);
        imagealphablending($image, false);
        imagesavealpha($image, true);
        ob_start();
        imagegif($image);
        $data =  ob_get_contents();
        ob_end_clean();
    }

    $pvars   = array('image' => base64_encode($data), 'key' => $api_key);
    $timeout = 30;
    $curl    = curl_init();
    $post    = http_build_query($pvars);

    curl_setopt($curl, CURLOPT_URL, 'http://imgur.com/api/upload.xml');
    curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $post);
    curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    $xml_raw = curl_exec($curl);
    curl_close ($curl);
    unlink($file);

    $xml = new SimpleXMLElement($xml_raw);

    if ($xml->error_code != '') {
        $imgur_error_code = $xml->error_code;
        $imgur_error_msg = $xml->error_msg;

        settype($imgur_error_code, "string");
        settype($imgur_error_msg, "string");

        echo "<h1>Error #" . $imgur_error_code . ", " . $imgur_error_msg . "</h1>";
    }
    else {
        imagedestroy($image);
        $imgur_original = $xml->original_image;
        $imgur_large_tbn = $xml->large_thumbnail;
        $imgur_small_tbn = $xml->small_thumbnail;
        $imgur_image_hash = $xml->image_hash;
        $imgur_delete_hash = $xml->delete_hash;
        $imgur_page = $xml->imgur_page;
        $img_delete_page = $xml->delete_page;

        settype($imgur_original, "string");
        settype($imgur_large_tbn, "string");
        settype($imgur_small_tbn, "string");

        ?>

        <script language="javascript">

        function insert_original()
        {
            var postCode = '<img src="<?php echo $imgur_original; ?>">';
            top.send_to_editor(postCode);
            return;
        }

        function insert_large_tbn()
        {
            var postCode = '<a href="<?php echo $imgur_original; ?>"><img src="<?php echo $imgur_large_tbn; ?>"></a>';
            top.send_to_editor(postCode);
            return;
        }

        function insert_small_tbn()
        {
            var postCode = '<a href="<?php echo $imgur_original; ?>"><img src="<?php echo $imgur_small_tbn; ?>"></a>';
            top.send_to_editor(postCode);
            return;
        }

        </script>

        <div align="center">

            <div id="insert_box_img">
                <h1>Small thumbnail :</h1>
                <img src="<?php echo $imgur_small_tbn ?>" border="0" />

                <h1>Large thumbnail :</h1>
                <img src="<?php echo $imgur_large_tbn ?>" border="0" />
            </div>

            <div id="insert_box_button">
            <h1>One-click insert into post...</h1>

            <input name="insert1" type="button" onclick="insert_original()" value="Original image" />
            <br/><br/>
            <input name="insert2" type="button" onclick="insert_large_tbn()" value="Large thumbnail w/ link to original" />
            <br/><br/>
            <input name="insert3" type="button" onclick="insert_small_tbn()" value="Small thumbnail w/ link to original" />

            </div>

            <div style="clear:both;"></div>

        </div>
        <?php
        }
        ?>
</body>
</html>

显示此错误 错误 #1003,不支持图像格式,或图像已损坏。

4

1 回答 1

1

api.php 正在使用 Imgur 的 API URL 的过时版本。读取的行

curl_setopt($curl, CURLOPT_URL, 'http://imgur.com/api/upload.xml');

应该改为

curl_setopt($curl, CURLOPT_URL, 'http://api.imgur.com/1/upload.xml');

于 2012-06-18T06:41:23.090 回答