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);



Leave a Comment.