Created
July 14, 2011 00:25
-
-
Save skipjac/1081630 to your computer and use it in GitHub Desktop.
Upload file to zendesk with PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$url = "http://skipjack.zendesk.com/uploads.xml?filename=dropbox1.html"; | |
$file = fopen("dropbox1.html", "r"); | |
$size = filesize($file); | |
$header= array('Content-type: application/binary' ); | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_USERPWD, "skip@youremail.net:passwrod"); | |
curl_setopt($ch, CURLOPT_URL, $url); | |
curl_setopt($ch, CURLOPT_POST ,1); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $header); | |
curl_setopt($ch, CURLOPT_POSTFIELDS ,$file); | |
curl_setopt($ch, CURLOPT_POST ,1); | |
curl_setopt($ch, CURLOPT_INFILE, $file); | |
curl_setopt($ch, CURLOPT_INFILESIZE, strlen($file)); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1); | |
curl_setopt($ch, CURLOPT_HEADER ,1); // DO NOT RETURN HTTP HEADERS | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL | |
$token = curl_exec($ch); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In 2023, the above code was not really working for me... it was almost working, uploading something, and returning JSON, but the uploaded image was blank. In the end, this is the only combination of CURL options that would work for me: