2020-04-16 10:41:25 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-04-16 10:41:25 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-04-16 10:41:25 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Utils;
|
|
|
|
|
|
|
|
class TempFile
|
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
public static function path($url) :string
|
|
|
|
{
|
2021-01-12 00:21:17 +01:00
|
|
|
$temp_path = @tempnam(sys_get_temp_dir() . '/' . sha1(time()), basename($url));
|
2020-09-06 11:38:10 +02:00
|
|
|
copy($url, $temp_path);
|
2020-04-16 10:41:25 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
return $temp_path;
|
|
|
|
}
|
2021-02-11 04:43:48 +01:00
|
|
|
|
|
|
|
/* Downloads a file to temp storage and returns the path - used for mailers */
|
2021-02-11 08:58:37 +01:00
|
|
|
public static function filePath($data, $filename) :string
|
2021-02-11 04:43:48 +01:00
|
|
|
{
|
|
|
|
|
2021-02-11 09:04:40 +01:00
|
|
|
$dir_hash = sys_get_temp_dir().'/'.sha1(microtime());
|
|
|
|
|
|
|
|
mkdir($dir_hash);
|
|
|
|
|
|
|
|
$file_path = $dir_hash . '/' . $filename;
|
2021-02-11 04:43:48 +01:00
|
|
|
|
|
|
|
file_put_contents($file_path, $data);
|
|
|
|
|
|
|
|
return $file_path;
|
|
|
|
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
}
|