Added archive.org upload
This commit is contained in:
@@ -37,6 +37,8 @@ class HTTPRequest {
|
||||
$this->body = substr($response, $header_size);
|
||||
$this->headers = [];
|
||||
|
||||
$hl = explode("\n", $header);
|
||||
|
||||
foreach ($hl as $h) {
|
||||
$h = trim($h);
|
||||
if (preg_match('/^HTTP\/([^\s]+)\s+(\d+)\s*/', $h, $m)) {
|
||||
@@ -109,4 +111,54 @@ class HTTPRequest {
|
||||
}
|
||||
|
||||
|
||||
public function put($url, $file, $headers = [], $headersonly = false) {
|
||||
|
||||
$fh = fopen($file, "r");
|
||||
|
||||
curl_reset($this->ch);
|
||||
curl_setopt($this->ch, CURLOPT_URL, $url);
|
||||
curl_setopt($this->ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:138.0) Gecko/20100101 Firefox/138.0");
|
||||
curl_setopt($this->ch, CURLOPT_PUT, true);
|
||||
curl_setopt($this->ch, CURLOPT_FILETIME, true);
|
||||
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, $this->connect_timeout);
|
||||
curl_setopt($this->ch, CURLOPT_TIMEOUT, $this->transfer_timeout);
|
||||
curl_setopt($this->ch, CURLOPT_HTTPHEADER, $headers);
|
||||
curl_setopt($this->ch, CURLOPT_NOBODY, $headersonly);
|
||||
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($this->ch, CURLOPT_HEADER, true);
|
||||
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, true);
|
||||
curl_setopt($this->ch, CURLOPT_INFILE, $fh);
|
||||
curl_setopt($this->ch, CURLOPT_INFILESIZE, filesize($file));
|
||||
|
||||
$this->status = 0;
|
||||
|
||||
$response = curl_exec($this->ch);
|
||||
|
||||
$header_size = curl_getinfo($this->ch, CURLINFO_HEADER_SIZE);
|
||||
$header = substr($response, 0, $header_size);
|
||||
$this->body = substr($response, $header_size);
|
||||
$this->headers = [];
|
||||
|
||||
|
||||
$hl = explode("\n", $header);
|
||||
|
||||
foreach ($hl as $h) {
|
||||
$h = trim($h);
|
||||
if (preg_match('/^HTTP\/([^\s]+)\s+(\d+)\s*/', $h, $m)) {
|
||||
$this->version = $m[1];
|
||||
$this->status = $m[2];
|
||||
continue;
|
||||
}
|
||||
if (str_starts_with($h, " ")) {
|
||||
$this->headers[$curr] .= " " . trim($h);
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^([^:]+):\s+(.*)$/', $h, $m)) {
|
||||
$curr = strtolower($m[1]);
|
||||
$this->headers[$curr] = $m[2];
|
||||
}
|
||||
}
|
||||
|
||||
return $this->status;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user