(PHP>=5) * fake excuse: I am not really a programmer, I am just learning...

I have read some files during my custom '/img' directory:

  • .digital
  • 1.digital
  • 2.digital
  • ....digital
  • 10.digital

And So I got an assortment()

I have to relabel the items in array based on their ID's known by jQuery (all file characteristics are occur HTML table cells, each getting ids and classes when needed). However the most annoying factor that I am unable to avoid file overwrites.

E.g. I relabel concurrently both 1.digital and three.digital (Using jQuery I have reassigned IDs (and new filenames where built and passed to create): 1-st file got ID=3, 3-rd file got ID=1 )

  • 1.digital -> 3.digital
  • ...
  • AND
  • ...
  • 3.digital -> 1.digital

You will see where's a trap.

So, now you ask ,: Must I create a '/temp' directory to prevent overwrites and also to email it, to relabel() or mv() them later? Or you will find a lot more transparent and faster methods to perform the same?

You will find a number of ways it can be done:

  • Move 3.digital to temp-dir
  • Relabel 1.digital to three.digital
  • Relabel 3.digital to at least one.digital
  • Move temp/1.digital to the folder

  • Relabel 3.digital to three.digital~
  • Relabel 1.digital to three.digital
  • Relabel 3.digital~ to at least one.digital

  • Load 3.digital in memory
  • Relabel 1.digital to three.digital
  • Produce a file 1.digital using the items in that old 3.digital (saved with you)

You will find most likely different options, however i think fundamental essentials best. Hope it's useful :)

-Edit- I believe the final the first is the quickest, however it consumes probably the most memory. If you do not like this, I'd make use of the second one. But that is your decision :)