The difference between creating a temporary file tempnam in php and tmpfile. The tempnam () function creates a temporary file with a unique file name. If yes, the function returns a new temporary file name. If it fails, false is returned. The tempnam () function creates a temporary file with a unique file name. If yes, the function returns a new temporary file name. If it fails, false is returned.
The tempnam () function creates a temporary file with a unique file name.
If yes, the function returns a new temporary file name. If it fails, false is returned.
Syntax
Tempnam (dir, prefix)
*/
Function dir_wriable ($ dir) // customize function extension to create a temporary file
{
$ Test = tempnam ("$ dir", "test_file"); // create a temporary file
If (fopen ($ test, "w"> $ fp = @ fopen ($ test, "w") // if the file is successfully opened
{
@ Fclose ($ fp); // close the file
@ Unlink ($ test); // delete an object
$ Wriable = "ture"; // The return value is true.
}
Else
{
$ Wriable = false or die ("cannot open $ test! "); // The returned value is false.
}
Return $ wriable; // returns a boolean value.
}
If (dir_wriable (str_replace ('/', '/', dirname (_ file _) // call a UDF
{
$ Dir_wriable = 'File created successfully ';
}
Else
{
$ Dir_wriable = 'File creation failed ';
}
/*
If the php Tutorial cannot create a file in the specified dir parameter, it is returned to the default value of the system.
Note: the behavior of this function has changed in version 4.0.3. A temporary file will also be created to avoid competition, that is, there may be a file with the same name in the file system between the string generated as the file name and the script to actually create the file. Note: If the file is no longer needed, the file will not be deleted automatically.
The tmpfile () function creates a temporary file with a unique file name in read/write (w +) mode.
The file will be automatically deleted after it is closed (with fclose (), or after the script is completed.
*/
$ Temp = tmpfile ();
Fwrite ($ temp, "testing, testing .");
// Returns the start of the file.
Rewind ($ temp );
// Read 1 k from the file
Echo fread ($ temp, 1024 );
// Delete an object
Fclose ($ temp );
The http://www.bkjia.com/PHPjc/632346.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632346.htmlTechArticletempnam () function creates a temporary file with a unique file name. If yes, the function returns a new temporary file name. If it fails, false is returned. The tempnam () function creates...