private function downloadFile(B2File $file) { $file->download(); die; }
/** * Uploads one file to B2, returning its unique file ID. * https://www.backblaze.com/b2/docs/b2_upload_file.html * @param string $uploadFileName - the name we wish to have for the file once uploaded. * @param string $filepath - the path to the file we wish to uplod * @param string $uploadAuthToken - // Provided by b2_get_upload_url * @param string $contentType - specify the mime type of the content. If not specified then * PHP will try to auto-detect it. * @return B2File */ public function uploadFile($uploadFileName, $filepath, UploadUrlResponse $uploadUrlResponse, $contentType = "") { if (!file_exists($filepath)) { throw new Exception("File [" . $filepath . "] does not exist."); } if ($contentType === "") { $contentType = mime_content_type($filepath); } $handle = fopen($filepath, 'r'); $read_file = fread($handle, filesize($filepath)); $content_type = "text/plain"; $sha1_of_file_data = sha1_file($filepath); $session = curl_init($uploadUrlResponse->getUploadUrl()); // Add read file as post field curl_setopt($session, CURLOPT_POSTFIELDS, $read_file); // Add headers $headers = array(); $headers[] = "Authorization: " . $uploadUrlResponse->getAuthorizationToken(); $headers[] = "X-Bz-File-Name: " . $uploadFileName; $headers[] = "Content-Type: " . $content_type; $headers[] = "X-Bz-Content-Sha1: " . $sha1_of_file_data; curl_setopt($session, CURLOPT_HTTPHEADER, $headers); curl_setopt($session, CURLOPT_POST, true); // HTTP POST curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Receive server response $server_output = curl_exec($session); // Let's do this! curl_close($session); // Clean up $responseObj = json_decode($server_output); $file = B2File::createFromUploadResponse($this, $responseObj); return $file; }