Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP tmpfile() returns false

I've got an image upload script which was previously working. It's now broken, and I've traced the problem down to one line:

$temp = tmpfile();
// $temp === false

The tmpfile() function is returning false. I can't seem to figure out why. I'm having a hard time wading through Google on this one.

The script it only broken on my local test environment, OSX 10.6.7, running MAMP 1.9.5. Fortunately the live site is working fine.

like image 693
Matt Avatar asked Jun 07 '11 15:06

Matt


People also ask

How to delete temp files PHP?

The temporary file is automatically removed when it is closed with fclose(), or when the script ends. The tmpfile() function returns Boolean False but many times it happens that it returns a non-Boolean value which evaluates to False.

How to create a temporary file PHP?

The tmpfile() function creates a temporary file with a unique name in read-write (w+) mode. Note: The file is automatically removed when closed, with fclose() or when the script ends. Tip: See also the tempnam() function.

What is file temp name in PHP?

Definition and UsageThe tempnam() function creates a temporary file with a unique name in the specified directory. Note: If the specified directory does not exist, tempnam() may generate a file in the system's temporary directory.

Where does PHP store temp files?

php stores all temporary files, that includes uploaded files, in the temporary files directory as specified in the php. ini.


1 Answers

tmpfile() returns false if it is unable to create the temporary file. Make sure your tmp folder is writable and try and check what sys_get_temp_dir() function returns.

like image 103
Niklas Avatar answered Sep 18 '22 01:09

Niklas