Well, rename is essentially the same as copy in terms of resource use.
copy is like get_original_file → save_another_file_with_the_same_name
rename is like get_original_file → save_another_file_with_a_different_name
How long it would take depends on How many files, How large the files are (weight, not dimensions), How busy the server is, How much memory is available.
Unless you’re dealing with small weight image files I recommend you do it in batches.
Especially if you’re on a shared host and you don’t want to risk getting them upset.
With those caveats in mind, there is ignore_user_abort
that could deal with the time out concern.
You’ll need to keep a note of how many images you’ve already copied, and start the loop at the next one. Your code is fine, but each time you load it, it will try to copy the same two images that it’s already copied. So one easy way might be instead of refreshing, have the code create a form with a submit button that contains a hidden form variable you can use as the loop start point. When you press the button, it re-calls the same code, which can read the start-point from the form variables, add 2 to it, do the job, and re-draw the form with the new start value. Or you could stick it in a session variable.
It is not. And rather the opposite. Just try it in your home PC and see.
Rename will take only a fraction of time because it takes to rewrite only disk index. While copying will be writing the actual contents of the every file.
@vinpkl if you need to do both tasks, then you need only the latter, because you can always give the new name when copy.
For only 2000 files better do it in one batch, without any HTML stuff to interfere.
I actually wrote a very similar thing, but I deleted it because, reading the doc for the PHP rename function, it does very much give the impression that it’s copying the file and deleting the original. Maybe it varies from OS to OS, but the fact it can rename from one disk partition to another suggests it is copying.
PHP is but a tiny wrapper around system calls or third-party apis. And for sure rename() doesn’t do anything of its own but calling an os routine. And every os renames a file by means of just rewriting an index table if happens within the same logical disc/partition or copy/erase otherwise.
Fair enough. It intrigued me, but not enough to start looking around to see if was easy to find source. It’s strange, though, that the manual page suggests that there was an enhancement to the php rename() function to support renaming between different disks, which if it only calls the underlying OS rename, would not be something that the php code has any influence on.