Upload a file on archive.org using php and curl

Archive.org provide you with a free to access online library of different kind of media, audio, movies, books, images …etc. You can upload your own file for free and make it available for everyone in different formats, for example uploading a mp3 audio file the servers will automatically convert it in ogg and vbr mp3 as well (check the faq for more info about derivatives) and afterward you will be able to download it with a direct link or with a torrent or even stream.

And here is a php code showing how to upload using CURL

//The file you want to upload and it should be inside the folder or add the path if it is somewhere else
$file = 'aa.png';
$file_read = fopen($file, 'r');

$headers = array(
'Authorization: LOW accesskey:secretkey',
'x-archive-meta-title:Tariq File'

$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, "http://s3.us.archive.org/myFolder/$file");

curl_setopt($ch, CURLOPT_PUT, true);
curl_setopt($ch, CURLOPT_INFILE, $file_read);
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($file));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_VERBOSE, false);


cURL Requests with PHP


cURL allows transfer of data across a wide variety of protocols, and is a very powerful system. It’s widely used as a way to send data across websites. cURL is unrestricted in what it can do, from the basic HTTP request, to the more complex FTP upload or interaction with an authentication enclosed HTTPS site.



Before we can do anything with a cURL request, we need to first instantiate an instance of cURL – we can do this by calling the function curl_init();, which returns a cURL resource. This function takes one parameter which is the URL that you want to send the request to, however, in our case, we’ll hold off doing that for now and set it an alternatively way later.

Continue reading