1

On one of my current projects, I am allowing users to upload images and set them as profile pictures.

The image initially will be stored in a temporary folder until the user crops & saves, or cancels the upload. Of course, there will be cases where they won't actually hit the cancel button. So I have to go through the temp folder and remove images not used after x minutes.

I can think of one way to do this, which would store the image data in MySQL, but I would rather just keep everything on Apache - though I'm not sure what language I'd use to actually perform the search and delete function.

Would this be a cron job?

Unheilig
  • 15,690
  • 193
  • 65
  • 96
  • Yes, a `cron` job would do just fine. Look at Linux' `find` command, it allows you to filter by modification/creation time and delete all in one command. – deceze Mar 12 '15 at 11:36

1 Answers1

1

If the crop and save function is all JS I would recommend you to use the users local file and upload on "save".

JavaScript:

function readURL(input) {
    if (input.files && input.files[0]) {
        var reader = new FileReader();

        reader.onload = function (e) {
            $('#blah').attr('src', e.target.result);
        }

        reader.readAsDataURL(input.files[0]);
    }
}    

// jQuery
$("#imgInp").change(function(){
    readURL(this);
});

// plain JS
document.getElementById('imgInp').onchange = function(){
      readURL(this);
}

HTML:

<form id="form1" runat="server">
    <input type='file' id="imgInp" />
    <img id="blah" src="#" alt="your image" />
</form>

jsfiddle

Credit to Preview an image before it is uploaded

Community
  • 1
  • 1
Marc
  • 3,645
  • 8
  • 31
  • 45