简体   繁体   中英

PHP Form - Fetch file and download using CURL

Now Delicious is closing down, I tried to make a PHP form for a few friends to use to download there bookmarks:

Vising this url: https://api.del.icio.us/v1/posts/all

You get prompted for a username and password then presented with XML, I want to automate the download of the XML returned.

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);

        $username = $_POST['username'];
        $password = $_POST['password'];
        $url = "https://api.del.icio.us/v1/posts/all"

?>
<form ACTION="<?php echo $PHP_SELF;?>" name="bookmarkform" METHOD="POST" align="center">
    <table>
        <tr>
            <td>
                <label>Username</label>
            </td>
            <td>
                <input NAME="username" tabindex="1">
            </td>
        </tr>
        <tr>
            <td>
                <label>Password</label>
            </td>
            <td>
                <input NAME="password" tabindex="2">
            </td>
        </tr>
        <tr>
            <td>
                &nbsp;
            </td>
            <td>
                <input TYPE="submit" tabindex="3" value="Submit!">
            </td>
        </tr>
    </table>
</form>

Im missing something here but cant see what? Any help appreciated : )

Well, I'm not familiar with Delicious API, but my first suggestions is not to use undefined variables:

    <?php
    $username = $_POST['username'];
    $password = $_POST['password'];
    $url = "https://api.del.icio.us/v1/posts/all"
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    $output = curl_exec($ch);
    $info = curl_getinfo($ch);
    curl_close($ch);

    ?>

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