views:

13

answers:

1

How can I display an image from file object? The file object holds the location of the image in temp uploaded directory.

I dont want to use any models.

Its for previewing a form having filefield

+2  A: 

The problem with most temporary files is that they don't exist. They're in a deleted state and will disappear entirely once the file handle is closed. It's your responsibility to move copy the data out of them and into another file, database, or cache, whatever works best, in order to preserve it.

You don't need to use any models to make this work, but you will need to be able to write to a directory your web server will be able to access. Typically you can make a /uploads directory and copy the file there, removing it later on when it is no longer required.

That clean-up step is easily done by a cron job that deletes all files with an mtime of a day or so, depending on your preference.

tadman
This is all good to know, regardless of the environment with which you are using to manipulate temp files.
fish2000