temporary-files

Create temporary file and auto removed

我们两清 提交于 2019-12-20 09:57:27
问题 I am writing a anti-leeching download script, and my plan is to create a temporary file, which is named by session ID, then after the session expires, the file will be automatically deleted. Is it possible ? And can you give me some tips how to do that in PHP ? Thanks so much for any reply 回答1: So we have one or more files available for download. Creating a temporary file for each download requests is not a good idea. Creating a symlink() for each file instead is a much better idea. This will

Removing created temp files in unexpected bash exit

一曲冷凌霜 提交于 2019-12-20 07:59:05
问题 I am creating temporary files from a bash script. I am deleting them at the end of the processing, but since the script is running for quite a long time, if I kill it or simply CTRL-C during the run, the temp files are not deleted. Is there a way I can catch those events and clean-up the files before the execution ends? Also, is there some kind of best practice for the naming and location of those temp files? I'm currently not sure between using: TMP1=`mktemp -p /tmp` TMP2=`mktemp -p /tmp` ..

How to display a repeated image stored in database on background as on Twitter?

安稳与你 提交于 2019-12-20 07:43:28
问题 I want to display an image on background (by using CSS repeat) the same way as on Twitter but the problem is that I am retrieving it from a MySQL database and CSS cannot handle the src tag on background. How can I retrieve an image from the MySQL database (I know how to display image by retrieving from database but here I want to display it differently), i.e display the image as backround on body and the image should repeat as if CSS repeat statement were used. Like on twitter.com. My code is

Python NamedTemporaryFile appears empty even after data is written

回眸只為那壹抹淺笑 提交于 2019-12-20 02:35:00
问题 In Python 2 it was easy to create a temporary file and access it. However with in Python 3 it seems that is no longer the case. I'm confused on how I can get to the file I create with tempfile.NamedTemporaryFile() so I can call a command on it. For example: temp = tempfile.NamedTemporaryFile() temp.write(someData) subprocess.call(['cat', temp.name]) # Doesn't print anything out as if file was empty (would work in python 2) subprocess.call(['cat', "%s%s" % (tempfile.gettempdir(), temp.name]))

Where does python tempfile writes its files?

一个人想着一个人 提交于 2019-12-19 08:16:17
问题 In python you can create a tempfile as follows: tempfile.TemporaryFile() And then you can write to it. Where is the file written in a GNU/Linux system? I can't seem to find it in the /tmp directory or any other directory. Thank you, 回答1: Looking at .name on a file handle is indeed one way to see where the file exists. In the case of TemporaryFile (on *NIX systems), you'll see <fdopen> , indicating an open file handle, but no corresponding directory entry. You'll need to use NamedTemporaryFile

ASP.NET Schedule deletion of temporary files

亡梦爱人 提交于 2019-12-19 03:53:51
问题 Question: I have an ASP.NET application which creates temporary PDF files (for the user to download). Now, many users over many days can create many PDFs, which take much disk space. What's the best way to schedule deletion of files older than 1 day/ 8 hours ? Preferably in the asp.net application itselfs... 回答1: For each temporary file that you need to create, make a note of the filename in the session: // create temporary file: string fileName = System.IO.Path.GetTempFileName(); Session

What is a safe way to create a Temp file in Java?

二次信任 提交于 2019-12-18 10:44:10
问题 I'm looking for a safe way to create a temp file in Java. By safe, I mean the following: Name should be unique, even under potential race conditions (e.g. another Thread calls the same func at the same time, or another process runs this code simultaneously) File should be private, even under potential race conditions (e.g. another user tries to chmod file at high rate) I can tell it to delete the file, without me having to do a generic delete, and risk deleting the wrong file Ideally, should

is there an existing FileInputStream delete on close?

淺唱寂寞╮ 提交于 2019-12-18 03:05:11
问题 Is there an existing way to have a FileInputStream delete the underlying file automatically when closed? I was planning to make my own utility class to extend FileInputStream and do it myself, but I'm kinda surprised that there isn't something already existing. edit: Use case is that I have a Struts 2 action that returns an InputStream for file download from a page. As far as I can tell, I don't get notified when the action is finished, or the FileInputStream is not in use anymore, and I don

How to create a temporary file that can be read by a subprocess?

南笙酒味 提交于 2019-12-17 17:45:12
问题 I'm writing a Python script that needs to write some data to a temporary file, then create a subprocess running a C++ program that will read the temporary file. I'm trying to use NamedTemporaryFile for this, but according to the docs, Whether the name can be used to open the file a second time, while the named temporary file is still open, varies across platforms (it can be so used on Unix; it cannot on Windows NT or later). And indeed, on Windows if I flush the temporary file after writing,

How to create temporary files on linux that will automatically clean up after themselves no matter what?

人盡茶涼 提交于 2019-12-14 03:47:01
问题 I want to create a temporary file on linux while making sure that the file will disappear after my program has terminated, even if it got killed or someone performs a hard reboot in the wrong moment. Does tmpfile() handle all this for me? 回答1: You seem pre-occupied with the idea that files might get left behind some how because of some race condition , I don't see an explanation of why this is a concern. "A race condition occurs when a program doesn't work as it's supposed to because of an