Note that there are some explanatory texts on larger screens.

plurals
  1. POProblem when uploading an image to tumblr using php/curl
    primarykey
    data
    text
    <p>I've been trying to create a simple php file that will upload a single image to tumblr. An example is listed <a href="http://www.tumblr.com/docs/en/api#api_write" rel="nofollow">here</a>, but it just won't work with images. Here is the code:</p> <pre><code>&lt;?php // Authorization info $tumblr_email = 'lol@something.com'; $tumblr_password = 'secret'; // Data for new record $post_type = 'photo'; //////////////////////THIS DOESN'T WORK///////////////////////////////// //$filename = "/Applications/MAMP/htdocs/1.jpeg"; //$handle = fopen($filename, "r"); //$post_data = fread($handle, filesize($filename)); //////////////////////NEITHER DOES THIS///////////////////////////////// //$post_data = "/Applications/MAMP/htdocs/1.jpg"; ///////////////////////////////NOR THIS///////////////////////////////// //$filename = "/Applications/MAMP/htdocs/1.jpeg"; //$post_data = fopen($filename, "r"); // Prepare POST request $request_data = http_build_query( array( 'email' =&gt; $tumblr_email, 'password' =&gt; $tumblr_password, 'type' =&gt; $post_type, 'data' =&gt; $post_data, 'generator' =&gt; 'testing tumblr API example' ) ); // Send the POST request (with cURL) $c = curl_init('http://www.tumblr.com/api/write'); curl_setopt($c, CURLOPT_POST, true); curl_setopt($c, CURLOPT_POSTFIELDS, $request_data); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $result = curl_exec($c); $status = curl_getinfo($c, CURLINFO_HTTP_CODE); curl_close($c); // Check for success if ($status == 201) { echo "Success! The new post ID is $result.\n"; } else if ($status == 403) { echo 'Bad email or password'; } else { echo "Error: $result\n"; } ?&gt; </code></pre> <p>I am not that familiar with php/curl, so I have no idea what am I doing wrong. This is also written on tumblr.com:</p> <blockquote> <p>File uploads can be done in a data parameter where specified above. You may use either of the common encoding methods:</p> <p>1) multipart/form-data method, like a file upload box in a web form. Maximum size:</p> <p>...10 MB for photos...</p> <p>This is recommended since there's much less overhead.</p> <p>2) Normal POST method, in which the file's entire binary contents are URL-encoded like any other POST variable. Maximum size:</p> <p>...5 MB for photos...</p> </blockquote> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload