Skip to content

Instantly share code, notes, and snippets.

@sh-sh-dev
Last active July 29, 2019 21:40
Show Gist options
  • Save sh-sh-dev/1adb729492f45660ac217902d3366801 to your computer and use it in GitHub Desktop.
Save sh-sh-dev/1adb729492f45660ac217902d3366801 to your computer and use it in GitHub Desktop.
transfer.sh
<?php
function Transfer($file, $name = null, $maxDownloads = null, $maxDays = null) {
$naf = false;
// If file doesn't exist, create a file with the $file content
if (!is_file($file)) {
$naf = true;
$cFile = !empty($name) ? $name : "Transfer-" . rand(1111, 9999) . ".tmp";
file_put_contents($cFile, $file);
$file = $cFile;
}
$file = new CURLFile($file);
$ch = curl_init("https://transfer.sh/");
curl_setopt($ch, CURLOPT_USERAGENT, "TransferFunction/1.0.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ["file" => $file]);
curl_setopt($ch, CURLOPT_HTTPHEADER, ["Max-Downloads: $maxDownloads", "Max-Days: $maxDays"]);
$link = curl_exec($ch);
curl_close($ch);
if ($naf) unlink($cFile);
return $link;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment