Secure temporary file: Difference between revisions

no edit summary
(added php)
No edit summary
Line 6:
This example creates a temporary file, writes to the file, then reads from the file.
 
<lang ada> with Ada.Text_Io; use Ada.Text_Io;
procedure Temp_File is
Line 19:
Get_Line(File => Temp, Item => Contents, Last => Length);
Put_Line(Contents(1..Length));
end Temp_File;</adalang>
 
=={{header|C}}==
<lang c>#include <stdio.h>
 
int main() {
Line 35:
return 0;
}</clang>
 
The following {{works with|POSIX}}
<lang c>#include <stdlib.h>
#include <stdio.h>
 
Line 49:
return 0;
}</clang>
 
=={{header|D}}==
{{works with|Tango}}
<lang d>module tempfile ;
import tango.io.TempFile, tango.io.Stdout ;
 
Line 67:
 
// both can only be accessed by the current user (the program?).
}</dlang>
 
=={{header|Haskell}}==
Line 79:
 
=={{header|Java}}==
<lang java>import java.io.File;
 
try {
Line 91:
 
} catch (IOException e) {
}</javalang>
 
=={{header|OCaml}}==
From the module Filename, one can use the functions [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Filename.html#VALtemp_file temp_file] or [http://caml.inria.fr/pub/docs/manual-ocaml/libref/Filename.html#VALopen_temp_file open_temp_file]
<lang ocaml>
# Filename.temp_file "prefix." ".suffix" ;;
- : string = "/home/blue_prawn/tmp/prefix.301f82.suffix"
</ocamllang>
 
=={{header|Perl}}==
function interface:
<lang perl>use File::Temp qw(tempfile);
$fh = tempfile();
($fh2, $filename) = tempfile(); # this file stays around by default
print "$filename\n";
close $fh;
close $fh2;</perllang>
 
object-oriented interface:
<lang perl>use File::Temp;
$fh = new File::Temp;
print $fh->filename, "\n";
close $fh;</perllang>
 
=={{header|PHP}}==
<lang php>$fh = tmpfile();
// do stuff with $fh
fclose($fh);
Line 124:
$filename = tempnam('/tmp', 'prefix');
echo "$filename\n";
// open $filename and do stuff with it</phplang>
 
=={{header|Python}}==