How to get a temporary file path?

I know you can create a temporary file with tmpfile and than write to it, and close it when it is not needed anymore. But the problem I have is that I need the absolute path to the file like this:


Can I somehow get the path, even with some other function or trick?


I want to be able to download the file from the database, but without

$fh = fopen("/var/www/html/myfile.xml", 'w') or die("no no");
fwrite($fh, $fileData);

because if I do it like this, there is a chance of overlapping, if more people try to download the same file at exactly the same time. Or am I wrong?


Maybe I can just generate unique(uniqID) filenames like that, and than delete them. Or can this be too consuming for the server if many people are downloading?


There are many ways you can achieve this, here is one

// Create a temporary file in the temporary 
// files directory using sys_get_temp_dir()
$temp_file = tempnam(sys_get_temp_dir(), 'MyFileName');

echo $temp_file;

The above example will output something similar to: /var/tmp/MyFileNameX322.tmp

Need Your Help

PHP function to retrieve specified SQL data

php mysql

So I tried making a function that retrieves data from database with the specified data that I want, but it doesn't work at all..

Unable to upload an APK file to hockey app via their API

android curl continuous-integration hockeyapp teamcity-9.0

I am unable to upload an android apk to hockeyapp through the API provided by them.When i use

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.