invoiceninja/app/Utils/TempFile.php

38 lines
893 B
PHP
Raw Permalink Normal View History

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
2023-01-29 09:21:40 +11:00
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
2021-06-16 16:58:16 +10:00
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Utils;
class TempFile
{
public static function path($url) :string
{
$temp_path = @tempnam(sys_get_temp_dir().'/'.sha1(time()), basename($url));
copy($url, $temp_path);
return $temp_path;
}
2021-02-11 14:43:48 +11:00
/* Downloads a file to temp storage and returns the path - used for mailers */
2021-02-11 18:58:37 +11:00
public static function filePath($data, $filename) :string
2021-02-11 14:43:48 +11:00
{
2021-02-11 19:04:40 +11:00
$dir_hash = sys_get_temp_dir().'/'.sha1(microtime());
mkdir($dir_hash);
$file_path = $dir_hash.'/'.$filename;
2021-02-11 14:43:48 +11:00
file_put_contents($file_path, $data);
return $file_path;
}
}