Correzioni minori su upload allegati da Applicazione

This commit is contained in:
Thomas Zilio 2020-08-10 12:14:56 +02:00
parent a309a24e8a
commit 1fc99b854e
2 changed files with 13 additions and 7 deletions

View File

@ -69,6 +69,13 @@ class AllegatiInterventi extends AppResource
return $record;
}
public static function getTempDirectory()
{
return DIRECTORY_SEPARATOR.
trim(sys_get_temp_dir(), DIRECTORY_SEPARATOR).
DIRECTORY_SEPARATOR;
}
public function createRecord($data)
{
$module = Modules::get('Interventi');
@ -79,19 +86,18 @@ class AllegatiInterventi extends AppResource
throw new InternalError();
}
$file = tmpfile();
$path = stream_get_meta_data($file)['uri'];
fwrite($file, base64_decode($content[1]));
$file = self::getTempDirectory().$data['nome'];
//$path = stream_get_meta_data($file)['uri'];
file_put_contents($file, base64_decode($content[1]));
// Salvataggio del file come allegato
$upload = Upload::build($path, [
$upload = Upload::build($file, [
'id_module' => $module['id'],
'id_record' => $data['id_intervento'],
'original_name' => $data['nome'],
], $data['nome'], $data['categoria']);
// Chiusura e rimozione del file temporaneo
fclose($file);
delete($file);
return [
'id' => $upload->id,

View File

@ -35,7 +35,7 @@ class Allegato extends Resource implements RetrieveInterface, CreateInterface
->where('id_record', $request['id_record'])
->first();
if (!empty($upload)) {
download(DOCROOT.'/'.$upload->filepath);
download(DOCROOT.'/'.$upload->filepath, $upload->original_name);
}
return [