0

I am allowing users to upload a profile picture of themselves. It involves these steps:

  1. User chooses an image file to upload
  2. Server receives the file through AJAX and stores with a name of temp_userid.jpg
  3. Server returns the image location to the page so the user can see it and make adjustments
  4. The user clicks Save Changes which posts back to the server as final confirmation of the image update
  5. Server loads the temp_userid.jpg, makes the adjustments e.g scale and crop, overwrites any existing profile image, and then finally deletes the temp_userid.jpg image

This works fine as long as the user saves his changes. If the user decides to leave the page, then the temp_userid.jpg file is still on the server and is never deleted. Some of the images can be over 5MB in size which I don't want on the server.

How could I go about cleansing the folders of temp files in a safe manner? I was thinking I could:

  1. Attempt to delete the temp image file whenever the user logs in to his account. The only slight issue here is that the user may never log-in again. But that could be dealt with using some kind of account expiration check.
  2. Attempt to delete all images with a prefix of 'temp_' from the server periodically. The risk here is that it deletes it while a user is still making adjustments to his image which would be terrible!

Are there any better ways of doing this? I'm tagging this as ColdFusion because thats the application server I'm using.

volume one
  • 6,800
  • 13
  • 67
  • 146
  • 2
    Why not delete all images that start with temp_ but are over a week old? – Matt Busche Feb 01 '15 at 17:09
  • @MattBusche could you suggest how/where this should be done? Should it be done Application.cfc OnRequestStart? – volume one Feb 01 '15 at 17:23
  • 1
    i'd use a scheduled task that searches the directories for anything more than a week old and deletes those images – Matt Busche Feb 01 '15 at 17:29
  • There is 1 folder per UserID. In that folder is where the temp image is stored that the user uploaded. How could I use to delete all images in all folders that begin with `temp_`? It wants a full path to be able to delete the file – volume one Feb 01 '15 at 17:33
  • 1
    Use cfdirectory with recursive on and cffile – Matt Busche Feb 01 '15 at 18:43

0 Answers0